Sha256: 12734037c4211c3513181c579eff96f7311d41ff4b6e043d60fd5266ed7bae71

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

#!/usr/bin/env ruby

# Copyright (C) 2016 Szymon Kopciewski
#
# This file is part of MayamlGetmail.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
require "mayaml-getmail"
require "fileutils"

def puts_ussage_message
  puts <<-END_HELP
    Ussage: mayaml-getmail <path_to_yaml_file> [<configs_destination_dir>]
  END_HELP
end

def present_configs(configs)
  configs.each do |name, config|
    puts "### Name: #{name} " + "=" * 50
    puts config
    puts
  end
end

def store_configs(configs, destination_dir)
  FileUtils.mkdir_p destination_dir
  configs.each do |name, config|
    file_path = File.join destination_dir, name.to_s
    File.open(file_path, "w") { |f| f.write(config) }
  end
end

def check_yaml_path(yaml_path)
  if yaml_path.nil?
    puts_ussage_message
    exit 1
  end
  unless File.exist? yaml_path
    puts "Could not find file: #{yaml_path}"
    exit 1
  end
end

def main(args)
  yaml_path = args.shift
  destination_dir = args.shift
  check_yaml_path yaml_path
  configs = MayamlGetmail.configs_from_file(yaml_path)
  destination_dir.nil? ? present_configs(configs) : store_configs(configs, destination_dir)
end

main ARGV

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mayaml-getmail-3.0.0 bin/mayaml-getmail
mayaml-getmail-1.0.3 bin/mayaml-getmail
mayaml-getmail-1.0.2 bin/mayaml-getmail
mayaml-getmail-1.0.1 bin/mayaml-getmail
mayaml-getmail-1.0.0 bin/mayaml-getmail