Module: Ronin::UI::CommandLine

Constants

COMMANDS_DIR
File.join('ronin','ui','command_line','commands')
DEFAULT_COMMAND
'console'

Public Visibility

Public Class Method Summary

commands

All command-line names of Commands available to the CommandLine.

Returns: Array

get_command(name)

Searches for a Command class with the matching command-line name.

Returns: Ronin::UI::Command

has_command?(name)

Searches for the command with the matching name.

Returns: Boolean

start(argv = ARGV)

Runs the CommandLine utility.

Returns: true

Public Class Method Details

commands

public Array commands

All command-line names of Commands available to the CommandLine.

Meta Tags

Returns:

[Array]

The command-line names of available Command classes.

[View source]


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ronin/ui/command_line/command_line.rb', line 41

def CommandLine.commands
  unless class_variable_defined?('@@ronin_commands')
    pattern = File.join('lib',COMMANDS_DIR,'*.rb')

    @@ronin_commands = Gem.find_resources(pattern).map { |path|
      File.basename(path).gsub(/\.rb$/,'')
    }.uniq
  end

  return @@ronin_commands
end

get_command

public Ronin::UI::Command get_command(name)

Searches for a Command class with the matching command-line name.

Meta Tags

Examples

  CommandLine.get_command('gen_overlay')
  # => Ronin::UI::CommandLine::Commands::GenOverlay
  CommandLine.get_command('gen-overlay')
  # => Ronin::UI::CommandLine::Commands::GenOverlay

Parameters:

[String, Symbol] name

The command-line name of the command to search for.

Returns:

[Ronin::UI::Command]

The Command registered with the command-line utility with the matching command-line name.

Raises:

[UnknownCommand]

No valid command could be found or loaded with the matching command-line name.

[View source]


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ronin/ui/command_line/command_line.rb', line 88

def CommandLine.get_command(name)
  name = name.to_s

  # eventually someone is going to use a space or - which is going
  # mess things up we will take care of this ahead of time here
  name.gsub!(/[\s-]/, '_')

  begin
    require File.join(COMMANDS_DIR,name)
  rescue Gem::LoadError => e
    raise(e)
  rescue ::LoadError
    raise(UnknownCommand,"unable to load the command #{name.dump}",caller)
  end

  class_name = name.to_const_string

  unless Commands.const_defined?(class_name)
    raise(UnknownCommand,"unknown command #{name.dump}",caller)
  end

  command = Commands.const_get(class_name)

  unless command.respond_to?(:start)
    raise(UnknownCommand,"command #{name.dump} must provide a 'start' method",caller)
  end

  return command
end

has_command?

public Boolean has_command?(name)

Searches for the command with the matching name.

Meta Tags

Parameters:

[String, Symbol] name

The name of the command to search for.

Returns:

[Boolean]

Specifies whether a command exists with the matching name.

[View source]


62
63
64
# File 'lib/ronin/ui/command_line/command_line.rb', line 62

def CommandLine.has_command?(name)
  CommandLine.commands.include?(name.to_s)
end

start

public true start(argv = ARGV)

Runs the CommandLine utility. If the first argument is a Command name, the CommandLine utility will attempt to find and run the Command with the matching command-line name. If the first argument is an option, or there are no arguments, the DEFAULT_COMMAND will be ran.

Meta Tags

Parameters:

[Array] argv

Command-line arguments which are used to select the Command to run, and which will be passed to the Command.

Returns:

[true]

The command was successfully ran.

[View source]


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/ronin/ui/command_line/command_line.rb', line 132

def CommandLine.start(argv=ARGV)
  if (argv.empty? || argv.first[0,1]=='-')
    name = DEFAULT_COMMAND
  else
    name = argv.first
    argv = argv[1..-1]
  end

  begin
    CommandLine.get_command(name).start(argv)
  rescue UnknownCommand => e
    STDERR.puts e
    exit -1
  end

  return true
end
Generated on Friday, September 25 2009 at 02:57:40 PM by YARD 0.2.3.5 (ruby-1.8.6).