Class: Ronin::Core::CLI::CommandShell::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/core/cli/command_shell/command.rb

Overview

Represents a defined command within a Ronin::Core::CLI::CommandShell class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, method_name: name, usage: nil, completions: nil, summary:, help: summary) ⇒ Command

Initializes a command value object.

Parameters:

  • name (Symbol)

    The name of the command.

  • method_name (Symbol) (defaults to: name)

    The command's method name. Defaults to the name argument.

  • usage (String, nil) (defaults to: nil)

    The usage string for the command's arguments.

  • completions (Array<String>, Symbol, nil) (defaults to: nil)

    Potential tab completion values, or a method name, to complete the command's arguments.

  • summary (String)

    A single line summary for the command.

  • help (String) (defaults to: summary)

    Multi-line help information for the command.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ronin/core/cli/command_shell/command.rb', line 82

def initialize(name, method_name: name,
                     usage:       nil,
                     completions: nil,
                     summary:     ,
                     help:        summary)
  @name        = name
  @method_name = method_name
  @usage       = usage
  @summary     = summary
  @help        = help
  @completions = completions
end

Instance Attribute Details

#completionsArray<String>, ... (readonly)

Possible tab completion values for the command's arguments.

Returns:

  • (Array<String>, Symbol, nil)


48
49
50
# File 'lib/ronin/core/cli/command_shell/command.rb', line 48

def completions
  @completions
end

#helpString (readonly)

The command's multi-line help output.

Returns:

  • (String)


58
59
60
# File 'lib/ronin/core/cli/command_shell/command.rb', line 58

def help
  @help
end

#method_nameSymbol (readonly)

The command's method name.

Returns:

  • (Symbol)


38
39
40
# File 'lib/ronin/core/cli/command_shell/command.rb', line 38

def method_name
  @method_name
end

#nameSymbol (readonly)

The command's name.

Returns:

  • (Symbol)


33
34
35
# File 'lib/ronin/core/cli/command_shell/command.rb', line 33

def name
  @name
end

#summaryString (readonly)

The command's one-line summary.

Returns:

  • (String)


53
54
55
# File 'lib/ronin/core/cli/command_shell/command.rb', line 53

def summary
  @summary
end

#usageString? (readonly)

The usage string for the command's arguments.

Returns:

  • (String, nil)


43
44
45
# File 'lib/ronin/core/cli/command_shell/command.rb', line 43

def usage
  @usage
end

Instance Method Details

#to_sString

Converts the command to a String.

Returns:

  • (String)

    The command name and the optional usage.



101
102
103
104
105
106
107
# File 'lib/ronin/core/cli/command_shell/command.rb', line 101

def to_s
  if @usage
    "#{@name} #{@usage}"
  else
    @name.to_s
  end
end