class Kojo::Commands::DirCmd

Handle calls to the +kojo dir+ command

Attributes

import_base[R]
indir[R]
opts[R]
outdir[R]

Public Instance Methods

run() click to toggle source
# File lib/kojo/commands/dir.rb, line 28
def run
  @opts = args['ARGS'].args_to_hash
  @indir = args['INDIR']
  @outdir = args['--save']
  @import_base = args['--imports']
  argfile = args['--args']

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

  run!
end

Private Instance Methods

run!() click to toggle source
# File lib/kojo/commands/dir.rb, line 45
def run!
  collection = Kojo::Collection.new @indir
  collection.import_base = import_base if import_base

  if outdir
    write collection
  else
    show collection
  end
end
show(collection) click to toggle source
# File lib/kojo/commands/dir.rb, line 56
def show(collection)
  collection.render @opts do |file, output|
    say "\n!txtgrn!# #{file}"
    say output
  end
end
write(collection) click to toggle source
# File lib/kojo/commands/dir.rb, line 63
def write(collection)
  collection.render @opts do |file, output|
    save "#{outdir}/#{file}", output
  end
end