Class: CodelessCode::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(command_name = $0, args = ARGV) ⇒ Cli

Returns a new instance of Cli.



21
22
23
24
# File 'lib/codeless_code/cli.rb', line 21

def initialize(command_name = $0, args = ARGV)
  @command_name = command_name
  @args = args
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/codeless_code/cli.rb', line 26

def call
  io = io_open

  if options.key?(:help)
    (io || $stdout).puts options.help
  elsif options.key?(:version)
    (io || $stdout).puts version_str
  elsif options.key?(:list_translations)
    Commands::ListTranslations.new(io: io).call
  else
    filter_fables(io)
  end

rescue Slop::Error => e
  warn format("%s\n\n%s", e, options.help)
  exit 1
ensure
  io&.close
end