Skip to content

Commit d815e42

Browse files
committed
Add a generic tab completion function
1 parent 1462330 commit d815e42

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,39 @@ def cmd_generate(*args)
153153
end
154154

155155
def cmd_generate_tabs(str, words)
156+
fmt = {
157+
'-b' => [ true ],
158+
'-E' => [ nil, ],
159+
'-e' => [ framework.encoders.map { |refname, mod| refname } ],
160+
'-h' => [ nil, ],
161+
'-o' => [ true, ],
162+
'-s' => [ true, ],
163+
'-f' => [ :file, ],
164+
'-t' => [ @@supported_formats, ],
165+
'-p' => [ true, ],
166+
'-k' => [ nil, ],
167+
'-x' => [ :file, ],
168+
'-i' => [ true, ]
169+
}
170+
tab_complete_spec(fmt, str, words)
171+
end
172+
173+
def tab_complete_spec(fmt, str, words)
156174
last_word = words[-1]
157-
fmt = @@generate_opts.fmt
158175
fmt = fmt.select { |key, value| last_word == key || !words.include?(key) }
159176

160-
option = fmt[last_word]
161-
return fmt.keys if !option || !option[0]
177+
val = fmt[last_word]
178+
return fmt.keys if !val # the last word does not look like a fmtspec
179+
arg = val[0]
180+
return fmt.keys if !arg # the last word is a fmtspec that takes no argument
162181

163182
tabs = []
164-
case last_word
165-
when '-e'
166-
tabs = framework.encoders.map { |refname, mod| refname }
167-
when '-f'
168-
tabs = tab_complete_filenames(str, words)
169-
when '-t'
170-
tabs = @@supported_formats
183+
if arg.to_s.to_sym == :file
184+
tabs = tab_complete_filenames(str, words)
185+
elsif arg.kind_of?(Array)
186+
tabs = arg.map {|a| a.to_s}
171187
end
188+
tabs
172189
end
173190
end
174191
end

0 commit comments

Comments
 (0)