Sha256: 0352f3eef06ad878e7e626df17c8c26e3fcfa06bf5f01f9e001002e0f5d928cc

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# Copyright (C) 2016, 2017, 2018 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
  return if File.exist? yaml_path
  puts "Could not find file: #{yaml_path}"
  exit 1
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

2 entries across 2 versions & 1 rubygems

Version Path
mayaml-getmail-4.0.4 bin/mayaml-getmail
mayaml-getmail-4.0.3 bin/mayaml-getmail