Class: Ronin::UI::CLI::ScriptCommand

Inherits:
ModelCommand show all
Defined in:
lib/ronin/ui/cli/script_command.rb

Overview

A base-command for querying and loading Scripts.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelCommand

each_query_option, model, #query, query_option, query_options, #setup

Methods inherited from Command

banner, command_name, #indent, inherited, #initialize, #print_array, #print_exception, #print_hash, #print_section, #print_title, #puts, run, #setup

Constructor Details

This class inherits a constructor from Ronin::UI::CLI::Command

Class Method Details

.script_class(script) ⇒ Script (protected)

Defines the class to load scripts from.

Parameters:

  • script (Script)

    The script class.

Returns:

  • (Script)

    The new script class.

Raises:

  • (ArgumentError)

    The given script class does not include Script.

Since:

  • 1.1.0



82
83
84
85
86
87
88
# File 'lib/ronin/ui/cli/script_command.rb', line 82

def self.script_class(script)
  unless script.included_modules.include?(Script)
    raise(ArgumentError,"#{script} does not include Ronin::Script")
  end

  model(script)
end

Instance Method Details

#executeObject

Loads the script, sets its parameters and runs the script.

Since:

  • 1.1.0.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ronin/ui/cli/script_command.rb', line 51

def execute
  script = load_script
  script.params = options[:params]

  if options.console?
    print_info "Starting the console with @script set ..."

    UI::Console.start(:script => script)
  else
    script.run
  end
end

#load_scriptScript? (protected)

Loads an script using the commands options.

Returns:

  • (Script, nil)

    The newly loaded script.

Raises:

  • (RuntimeError)

    The script class did not define the query method for one of the query options.

Since:

  • 1.1.0



104
105
106
107
108
109
110
# File 'lib/ronin/ui/cli/script_command.rb', line 104

def load_script
  if options[:file]
    self.class.model.load_from(options[:file])
  else
    query.load_first
  end
end