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
All command-line names of Commands available to the CommandLine.
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
Searches for a Command class with the matching command-line name.
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?
Searches for the command with the matching name.
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
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.
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 |