Skip to content

Commit c4a6b8b

Browse files
committed
pySim-shell: obey quit command in startup commands+scripts
Startup scripts are executed using the cmd2 provided onecmd_plus_hooks method. This method can run arbitrary commands, which also includes the command "run_scrit" that we use to execute startup scripts. When a script executes a quit command, or when someone issues a quit command using the --execute-command or the command argument, then this commands is executed. However a quit command won't actually quit the process. All it does is to change the return code of app.onecmd_plus_hooks (see [1]). So we must evaluate the return code and take care of the quitting ourselves. [1] https://cmd2.readthedocs.io/en/0.9.15/api/cmd.html#cmd2.cmd2.Cmd.onecmd_plus_hooks Related: OS#6731 Change-Id: Ic6e9c54cdb6955d65011af3eb5a025eee5da4143
1 parent de91b0d commit c4a6b8b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pySim-shell.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1159,14 +1159,18 @@ def receive_fetch(self, pcmd: ProactiveCommand):
11591159
# Run optional commands
11601160
for c in opts.execute_command:
11611161
if not startup_errors:
1162-
app.onecmd_plus_hooks(c)
1162+
stop = app.onecmd_plus_hooks(c)
1163+
if stop == True:
1164+
sys.exit(0)
11631165
else:
11641166
print("Errors during startup, refusing to execute command (%s)" % c)
11651167

11661168
# Run optional command
11671169
if opts.command:
11681170
if not startup_errors:
1169-
app.onecmd_plus_hooks('{} {}'.format(opts.command, ' '.join(opts.command_args)))
1171+
stop = app.onecmd_plus_hooks('{} {}'.format(opts.command, ' '.join(opts.command_args)))
1172+
if stop == True:
1173+
sys.exit(0)
11701174
else:
11711175
print("Errors during startup, refusing to execute command (%s)" % opts.command)
11721176

@@ -1177,7 +1181,9 @@ def receive_fetch(self, pcmd: ProactiveCommand):
11771181
print("Error: script file (%s) not readable!" % opts.script)
11781182
startup_errors = True
11791183
else:
1180-
app.onecmd_plus_hooks('{} {}'.format('run_script', opts.script), add_to_history = False)
1184+
stop = app.onecmd_plus_hooks('{} {}'.format('run_script', opts.script), add_to_history = False)
1185+
if stop == True:
1186+
sys.exit(0)
11811187
else:
11821188
print("Errors during startup, refusing to execute script (%s)" % opts.script)
11831189

0 commit comments

Comments
 (0)