Class: Lono::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/lono/command.rb

Direct Known Subclasses

CLI, Cfn, Completion, Param, Script, Template, Upgrade

Class Method Summary collapse

Class Method Details

.alter_command_description(command) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lono/command.rb', line 55

def alter_command_description(command)
  return unless command

  # Add description to beginning of long_description
  long_desc = if command.long_description
      "#{command.description}\n\n#{command.long_description}"
    else
      command.description
    end

  # add reference url to end of the long_description
  unless website.empty?
    full_command = [command.ancestor_name, command.name].compact.join('-')
    url = "#{website}/reference/lono-#{full_command}"
    long_desc += "\n\nAlso available at: #{url}"
  end

  command.long_description = long_desc
end

.command_help(shell, command_name) ⇒ Object

Override command_help to include the description at the top of the long_description.



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

def command_help(shell, command_name)
  meth = normalize_command_name(command_name)
  command = all_commands[meth]
  alter_command_description(command)
  super
end

.dispatch(m, args, options, config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lono/command.rb', line 19

def dispatch(m, args, options, config)
  # Allow calling for help via:
  #   lono command help
  #   lono command -h
  #   lono command --help
  #   lono command -D
  #
  # as well thor's normal way:
  #
  #   lono help command
  help_flags = Thor::HELP_MAPPINGS + ["help"]
  if args.length > 1 && !(args & help_flags).empty?
    args -= help_flags
    args.insert(-2, "help")
  end

  #   lono version
  #   lono --version
  #   lono -v
  version_flags = ["--version", "-v"]
  if args.length == 1 && !(args & version_flags).empty?
    args = ["version"]
  end

  super
end

.websiteObject



76
77
78
# File 'lib/lono/command.rb', line 76

def website
  "http://lono.cloud"
end