Skip to content

Commit feb1394

Browse files
committed
Land rapid7#6752, compact table for advanced options
2 parents 16c5998 + 8cc1d2e commit feb1394

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,15 @@ def self.dump_options(mod, indent = '', missing = false)
400400
'Description'
401401
])
402402

403-
mod.options.sorted.each { |entry|
404-
name, opt = entry
403+
mod.options.sorted.each do |name, opt|
405404
val = mod.datastore[name] || opt.default
406405

407406
next if (opt.advanced?)
408407
next if (opt.evasion?)
409408
next if (missing && opt.valid?(val))
410409

411410
tbl << [ name, opt.display_value(val), opt.required? ? "yes" : "no", opt.desc ]
412-
}
411+
end
413412

414413
return tbl.to_s
415414
end
@@ -420,24 +419,23 @@ def self.dump_options(mod, indent = '', missing = false)
420419
# @param indent [String] the indentation to use.
421420
# @return [String] the string form of the information.
422421
def self.dump_advanced_options(mod, indent = '')
423-
output = ''
424-
pad = indent
425-
426-
mod.options.sorted.each { |entry|
427-
name, opt = entry
428-
429-
next if (!opt.advanced?)
430-
431-
val = mod.datastore[name] || opt.default.to_s
432-
desc = word_wrap(opt.desc, indent.length + 3)
433-
desc = desc.slice(indent.length + 3, desc.length)
422+
tbl = Rex::Ui::Text::Table.new(
423+
'Indent' => indent.length,
424+
'Columns' =>
425+
[
426+
'Name',
427+
'Current Setting',
428+
'Required',
429+
'Description'
430+
])
434431

435-
output << pad + "Name : #{name}\n"
436-
output << pad + "Current Setting: #{val}\n"
437-
output << pad + "Description : #{desc}\n"
438-
}
432+
mod.options.sorted.each do |name, opt|
433+
next unless opt.advanced?
434+
val = mod.datastore[name] || opt.default
435+
tbl << [ name, opt.display_value(val), opt.required? ? "yes" : "no", opt.desc ]
436+
end
439437

440-
return output
438+
return tbl.to_s
441439
end
442440

443441
# Dumps the evasion options associated with the supplied module.
@@ -446,25 +444,23 @@ def self.dump_advanced_options(mod, indent = '')
446444
# @param indent [String] the indentation to use.
447445
# @return [String] the string form of the information.
448446
def self.dump_evasion_options(mod, indent = '')
449-
output = ''
450-
pad = indent
451-
452-
mod.options.sorted.each { |entry|
453-
name, opt = entry
454-
455-
next if (!opt.evasion?)
456-
457-
val = mod.datastore[name] || opt.default || ''
458-
459-
desc = word_wrap(opt.desc, indent.length + 3)
460-
desc = desc.slice(indent.length + 3, desc.length)
447+
tbl = Rex::Ui::Text::Table.new(
448+
'Indent' => indent.length,
449+
'Columns' =>
450+
[
451+
'Name',
452+
'Current Setting',
453+
'Required',
454+
'Description'
455+
])
461456

462-
output << pad + "Name : #{name}\n"
463-
output << pad + "Current Setting: #{val}\n"
464-
output << pad + "Description : #{desc}\n"
465-
}
457+
mod.options.sorted.each do |name, opt|
458+
next unless opt.evasion?
459+
val = mod.datastore[name] || opt.default
460+
tbl << [ name, opt.display_value(val), opt.required? ? "yes" : "no", opt.desc ]
461+
end
466462

467-
return output
463+
return tbl.to_s
468464
end
469465

470466
# Dumps the references associated with the supplied module.

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,15 +828,15 @@ def cmd_options(*args)
828828
end
829829
end
830830

831-
args.each { |name|
831+
args.each do |name|
832832
mod = framework.modules.create(name)
833833

834834
if (mod == nil)
835835
print_error("Invalid module: #{name}")
836836
else
837837
show_options(mod)
838838
end
839-
}
839+
end
840840
end
841841

842842
#
@@ -2600,9 +2600,9 @@ def cmd_unset(*args)
26002600
# Tab completion for the unset command
26012601
#
26022602
# @param str [String] the string currently being typed before tab was hit
2603-
# @param words [Array<String>] the previously completed words on the command line. words is always
2604-
# at least 1 when tab completion has reached this stage since the command itself has been completed
2605-
2603+
# @param words [Array<String>] the previously completed words on the command
2604+
# line. `words` is always at least 1 when tab completion has reached this
2605+
# stage since the command itself has been completed.
26062606
def cmd_unset_tabs(str, words)
26072607
datastore = active_module ? active_module.datastore : self.framework.datastore
26082608
datastore.keys

0 commit comments

Comments
 (0)