#!/usr/bin/env ruby # Copyright (C) 2016 Szymon Kopciewski # # This file is part of MayamlMutt. # # 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 . # require "mayaml-mutt" require "fileutils" def puts_ussage_message puts <<-END_HELP Ussage: mayaml-mutt-init [] 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 = MayamlMutt.accounts_creds_from_file(yaml_path) destination_dir.nil? ? present_configs(configs) : store_configs(configs, destination_dir) end main ARGV