Skip to content

Commit 27a007f

Browse files
committed
Land rapid7#9432, cmd_edit improvements (again!)
We seem to enjoy refactoring this method.
2 parents 38d056b + a255586 commit 27a007f

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,38 @@ def cmd_edit_help
7777
# Edit the currently active module or a local file
7878
#
7979
def cmd_edit(*args)
80+
editing_module = false
81+
8082
if args.length > 0
8183
path = args[0]
8284
elsif active_module
85+
editing_module = true
8386
path = active_module.file_path
8487
end
8588

86-
if path
87-
editor = local_editor
89+
if path.nil?
90+
print_error('Nothing to edit. Try using a module first or specifying a library file to edit.')
91+
return
92+
end
8893

89-
if editor.nil?
90-
editor = 'vim'
91-
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
92-
end
94+
editor = local_editor
9395

94-
print_status("Launching #{editor} #{path}")
95-
system(*editor.split, path)
96+
if editor.nil?
97+
editor = 'vim'
98+
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
99+
end
96100

97-
# XXX: This will try to reload *any* .rb and break on modules
98-
if args.length > 0 && path.end_with?('.rb')
99-
print_status("Reloading #{path}")
100-
load path
101-
else
102-
print_error('Only Ruby files can be reloaded (use reload/rerun for modules)')
103-
end
101+
print_status("Launching #{editor} #{path}")
102+
system(*editor.split, path)
103+
104+
return if editing_module
105+
106+
# XXX: This will try to reload *any* .rb and break on modules
107+
if path.end_with?('.rb')
108+
print_status("Reloading #{path}")
109+
load path
104110
else
105-
print_error('Nothing to edit -- try using a module first.')
111+
print_error('Only library files can be reloaded after editing.')
106112
end
107113
end
108114

0 commit comments

Comments
 (0)