Class: Ronin::UI::CLI::Commands::Exec

Inherits:
Object
  • Object
show all
Includes:
Output::Helpers
Defined in:
lib/ronin/ui/cli/commands/exec.rb

Overview

The ronin exec command.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, arguments = []) ⇒ Exec

Initializes the exec command.

Parameters:

  • script (String)

    The name or path of the script to run.

  • arguments (Array<String>) (defaults to: [])

    The arguments to the script with.

Since:

  • 1.0.0


46
47
48
49
# File 'lib/ronin/ui/cli/commands/exec.rb', line 46

def initialize(script,arguments=[])
  @script = script
  @arguments = arguments
end

Class Method Details

.start(argv = ARGV) ⇒ Object

Runs the exec command.

Parameters:

  • argv (Array<String>) (defaults to: ARGV)

    The arguments to run the exec command with.


57
58
59
60
61
62
63
64
65
66
# File 'lib/ronin/ui/cli/commands/exec.rb', line 57

def self.start(argv=ARGV)
  case argv[0]
  when '-h', '--help', nil
    puts "Usage:\n  ronin-exec SCRIPT [ARGS...]\n\n"
    puts "Runs a script from a Ronin Repository"
    return false
  end

  self.new(argv[0],argv[1..-1]).execute
end

Instance Method Details

#executeObject

Executes the exec command.

Since:

  • 1.0.0


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ronin/ui/cli/commands/exec.rb', line 73

def execute
  if File.file?(@script)
    require 'ronin'

    setup_argv { load File.expand_path(@script) }
    return true
  end

  Database.setup

  Repository.each do |repo|
    path = repo.path.join(Repository::BIN_DIR,@script)

    if path.file?
      require 'ronin'

      repo.activate!

      setup_argv { load path }
      return true
    end
  end

  print_error "Could not find the script #{@script.dump}."
  return false
end

#setup_argvObject (protected)

Temporarily populates the ARGV constant.

Since:

  • 1.0.0


107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ronin/ui/cli/commands/exec.rb', line 107

def setup_argv
  original_argv = ARGV.dup
  ARGV.clear
  @arguments.each { |arg| ARGV << arg }

  result = yield

  ARGV.clear
  original_argv.each { |arg| ARGV << arg }
  return result
end