Class: Ronin::UI::CommandLine::Command
- Thor
- Ronin::UI::CommandLine::Command
Included Modules
Thor::Actions, Ronin::UI::Output::Helpers
Constructor Summary
Creates a new Command object.
49 50 51 52 53 |
# File 'lib/ronin/ui/command_line/command.rb', line 49 def initialize(arguments=[],={},config={}) @indent = 0 super(arguments,,config) end |
Public Visibility
Public Class Method Summary
| start(arguments = ARGV, config = {}) |
|---|
Public Instance Method Summary
| #default(*arguments) |
Default method to call after the options have been parsed. |
|---|---|
| #help |
Prints the help information for the command and exists. |
Public Class Method Details
start
55 56 57 58 59 60 61 |
# File 'lib/ronin/ui/command_line/command.rb', line 55 def self.start(arguments=ARGV,config={}) unless map[arguments.first.to_s] arguments = [default_task] + arguments end super(arguments,config) end |
Public Instance Method Details
default
Default method to call after the options have been parsed.
87 88 |
# File 'lib/ronin/ui/command_line/command.rb', line 87 def default(*arguments) end |
help
Prints the help information for the command and exists.
95 96 97 98 99 100 101 102 103 |
# File 'lib/ronin/ui/command_line/command.rb', line 95 def help self.class.help( shell, self.class.default_task, :short => false, :ident => 2, :namespace => false ) end |
Protected Visibility
Protected Instance Method Summary
| #indent(n = 2, &block) |
Increases the indentation out output temporarily. Returns: nil |
|---|---|
| #name |
Returns the name of the command. |
| #print_array(array, options = {}) |
Prints a given Array. Returns: nil |
| #print_hash(hash, options = {}) |
Prints a given Hash. Returns: nil |
| #print_title(title) |
Prints a given title. |
| #puts(*messages) |
Print the given messages with indentation. |
Protected Instance Methods Included from Ronin::UI::Output::Helpers
Protected Instance Method Details
indent
Increases the indentation out output temporarily.
127 128 129 130 131 132 133 134 |
# File 'lib/ronin/ui/command_line/command.rb', line 127 def indent(n=2,&block) @indent += n block.call() @indent -= n return nil end |
name
Returns the name of the command.
110 111 112 |
# File 'lib/ronin/ui/command_line/command.rb', line 110 def name self.class.name.split('::').last.snake_case end |
print_array
Prints a given Array.
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ronin/ui/command_line/command.rb', line 170 def print_array(array,={}) print_title([:title]) if [:title] indent do array.each { |value| puts value } end puts "\n" if [:title] return nil end |
print_hash
Prints a given Hash.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ronin/ui/command_line/command.rb', line 195 def print_hash(hash,={}) align = hash.keys.map { |name| name.to_s.length }.max print_title([:title]) if [:title] indent do hash.each do |name,value| name = "#{name}:".ljust(align) puts "#{name}\t#{value}" end end puts "\n" if [:title] return nil end |
print_title
Prints a given title.
152 153 154 |
# File 'lib/ronin/ui/command_line/command.rb', line 152 def print_title(title) puts "[ #{title} ]" end |
puts
Print the given messages with indentation.
142 143 144 |
# File 'lib/ronin/ui/command_line/command.rb', line 142 def puts(*) super(*(.map { |mesg| (' ' * @indent) + mesg.to_s })) end |