Exception: Rodish::CommandFailure

Inherits:
CommandExit
  • Object
show all
Defined in:
lib/rodish/errors.rb

Overview

Rodish::CommandFailure is used for failures of commands, such as:

  • Invalid options

  • Invalid number of arguments for a command

  • Invalid subcommands

  • No subcommand given for a command that only supports subcommands

Direct Known Subclasses

ProgramBug

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, command = nil) ⇒ CommandFailure

Returns a new instance of CommandFailure.



31
32
33
34
# File 'lib/rodish/errors.rb', line 31

def initialize(message, command=nil)
  @command = command
  super(message)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



29
30
31
# File 'lib/rodish/errors.rb', line 29

def command
  @command
end

Instance Method Details

#failure?Boolean

Always returns false, since CommandFailure represents failures.

Returns:

  • (Boolean)


37
38
39
# File 'lib/rodish/errors.rb', line 37

def failure?
  true
end

#message_with_usageObject

Return the message along with the content of any related option parsers. This can be used to show usage an options along with error messages for failing commands.



44
45
46
47
48
49
50
51
# File 'lib/rodish/errors.rb', line 44

def message_with_usage
  help = @command&.help || ''
  if help.empty?
    message
  else
    "#{message}\n\n#{help}"
  end
end