Skip to content

Commit a255586

Browse files
committed
Refactor to use guard clauses
1 parent df71def commit a255586

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,37 @@ def cmd_edit_help
7878
#
7979
def cmd_edit(*args)
8080
editing_module = false
81+
8182
if args.length > 0
8283
path = args[0]
8384
elsif active_module
8485
editing_module = true
8586
path = active_module.file_path
8687
end
8788

88-
if path
89-
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
9093

91-
if editor.nil?
92-
editor = 'vim'
93-
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
94-
end
94+
editor = local_editor
95+
96+
if editor.nil?
97+
editor = 'vim'
98+
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
99+
end
95100

96-
print_status("Launching #{editor} #{path}")
97-
system(*editor.split, path)
101+
print_status("Launching #{editor} #{path}")
102+
system(*editor.split, path)
98103

99-
# XXX: This will try to reload *any* .rb and break on modules
100-
if !editing_module
101-
if path.end_with?('.rb')
102-
print_status("Reloading #{path}")
103-
load path
104-
else
105-
print_error("Only library files can be reloaded after editing (use reload/rerun for modules)")
106-
end
107-
end
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
108110
else
109-
print_error('Nothing to edit -- try using a module first, or specifying a library file to edit.')
111+
print_error('Only library files can be reloaded after editing.')
110112
end
111113
end
112114

0 commit comments

Comments
 (0)