Class: Cure::Cli::Command

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/cure/cli/command.rb

Direct Known Subclasses

GenerateCommand, NewCommand, RunCommand

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Log

#log_debug, #log_error, #log_info, #log_trace, #log_warn

Constructor Details

#initialize(argv = []) ⇒ Command

Returns a new instance of Command.

Parameters:

  • argv (Array) (defaults to: [])


38
39
40
# File 'lib/cure/cli/command.rb', line 38

def initialize(argv = [])
  @argv = argv
end

Class Method Details

.invoke(command, argv) ⇒ Object

Parameters:

  • command (String)
  • argv (Array)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cure/cli/command.rb', line 13

def self.invoke(command, argv)
  extend Log

  handler = nil

  case command
  when "new"
    handler = NewCommand.new(argv)
  when "generate"
      handler = GenerateCommand.new(argv)
  when "run"
    handler = RunCommand.new(argv)
  else
    new.help
    return
  end

  handler.call
rescue ArgumentError => aex
  handler ? handler.help(ex: aex) : new.help
rescue StandardError => ex
  log_error(ex.message)
end

Instance Method Details

#callObject



42
43
44
45
# File 'lib/cure/cli/command.rb', line 42

def call
  validate
  execute
end

#help(ex: nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/cure/cli/command.rb', line 47

def help(ex: nil)
  log_error ex.message if ex && ex.is_a?(StandardError)
  log_error "Error: unknown request"
  log_info "\nUsage: cure <command> [options]"
  log_info "\tRun:         cure run -t [template] -f [file]"
  log_info "\tNew Project: cure new [name]"
end