Class: Kojo::Commands::FileCmd

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

Overview

Handle calls to the kojo file command

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#import_baseObject (readonly)

Returns the value of attribute import_base.



6
7
8
# File 'lib/kojo/commands/file.rb', line 6

def import_base
  @import_base
end

#infileObject (readonly)

Returns the value of attribute infile.



6
7
8
# File 'lib/kojo/commands/file.rb', line 6

def infile
  @infile
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/kojo/commands/file.rb', line 6

def opts
  @opts
end

#outfileObject (readonly)

Returns the value of attribute outfile.



6
7
8
# File 'lib/kojo/commands/file.rb', line 6

def outfile
  @outfile
end

Instance Method Details

#run(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kojo/commands/file.rb', line 24

def run(args)
  @opts = args['ARGS'].args_to_hash
  @outfile = args['--save']
  @infile = args['INFILE']
  @import_base = args['--imports']
  argfile = args['--args']

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

  run!
end

#run!Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kojo/commands/file.rb', line 39

def run!
  template = Kojo::Template.new infile
  template.import_base = import_base if import_base
  output = template.render(opts)

  if outfile
    File.write outfile, output
    say "Saved #{outfile}"
  else
    puts output
  end
end