Class: Kubes::Command

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

Direct Known Subclasses

CLI, Kubes::CLI::Docker, Kubes::CLI::New

Class Method Summary collapse

Class Method Details

.alter_command_description(command) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kubes/command.rb', line 74

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/kubes-#{full_command}"
    long_desc += "\n\nHelp also available at: #{url}"
  end

  command.long_description = long_desc
end

.check_project!(command_name) ⇒ Object



59
60
61
62
63
# File 'lib/kubes/command.rb', line 59

def check_project!(command_name)
  return if command_name.nil?
  return if %w[-h -v --version completion completion_script help init new version].include?(command_name)
  Kubes.check_project!
end

.command_help(shell, command_name) ⇒ Object

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



67
68
69
70
71
72
# File 'lib/kubes/command.rb', line 67

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kubes/command.rb', line 30

def dispatch(m, args, options, config)
  check_project!(args.first)

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

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

  super
end

.exit_on_failure?Boolean

github.com/erikhuda/thor/issues/244 Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define ‘exit_on_failure?` in `Lono::CLI` You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.

Returns:

  • (Boolean)


103
104
105
# File 'lib/kubes/command.rb', line 103

def exit_on_failure?
  true
end

.websiteObject

meant to be overriden



96
97
98
# File 'lib/kubes/command.rb', line 96

def website
  ""
end