Class: Kojo::Commands::ConfigCmd

Inherits:
MisterBin::Command
  • Object
show all
Includes:
Colsole
Defined in:
lib/kojo/commands/config.rb

Instance Method Summary collapse

Instance Method Details

#run(args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kojo/commands/config.rb', line 23

def run(args)
  gen = Kojo::Generator.new args['CONFIG']
  outdir = args['--save']
  opts = args['ARGS'].args_to_hash
  argfile = args['--args']

  if argfile
    fileopts = YAML.load_file(argfile).symbolize_keys
    opts = fileopts.merge opts
  end

  gen.generate opts do |file, output|
    path = "#{outdir}/#{file}"
    if outdir
      dir = File.dirname path
      FileUtils.mkdir_p dir unless Dir.exist? dir

      File.write path, output
      say "Saved #{path}"
    else
      say "\n!txtgrn!# #{file}"
      say output
    end
  end
end