Skip to content

Commit e40c771

Browse files
committed
Merge branch 'main' into multiline_history
2 parents 75c73e9 + 5cb62a5 commit e40c771

File tree

8 files changed

+1
-77
lines changed

8 files changed

+1
-77
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ prompt is displayed.
6060
- Replaced `async_alert()` and `async_update_prompt()` with a single function called
6161
`add_alert()`. This new function is thread-safe and does not require you to acquire a mutex
6262
before calling it like the previous functions did.
63+
- Removed `Cmd.default_to_shell`.
6364
- Enhancements
6465
- New `cmd2.Cmd` parameters
6566
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These

cmd2/cmd2.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ def __init__(
413413
self.stdout = sys.stdout
414414

415415
# Attributes which should NOT be dynamically settable via the set command at runtime
416-
self.default_to_shell = False # Attempt to run unrecognized commands as shell commands
417416
self.allow_redirection = allow_redirection # Security setting to prevent redirection of stdout
418417

419418
# If True, cmd2 treats redirected input (pipes/files) as an interactive session.
@@ -2277,9 +2276,6 @@ def _perform_completion(
22772276
completer_func = self.completedefault # type: ignore[assignment]
22782277

22792278
# Not a recognized macro or command
2280-
# Check if this command should be run as a shell command
2281-
elif self.default_to_shell and command in utils.get_exes_in_path(command):
2282-
completer_func = self.path_complete
22832279
else:
22842280
completer_func = self.completedefault # type: ignore[assignment]
22852281

@@ -3199,11 +3195,6 @@ def default(self, statement: Statement) -> bool | None:
31993195
32003196
:param statement: Statement object with parsed input
32013197
"""
3202-
if self.default_to_shell:
3203-
if 'shell' not in self.exclude_from_history:
3204-
self.history.append(statement)
3205-
return self.do_shell(statement.command_and_args)
3206-
32073198
err_msg = self.default_error.format(statement.command)
32083199
if self.suggest_similar_command and (suggested_command := self._suggest_similar_command(statement.command)):
32093200
err_msg += f"\n{self.default_suggestion_message.format(suggested_command)}"

docs/features/initialization.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Here are instance attributes of `cmd2.Cmd` which developers might wish to overri
3131
- **debug**: if `True`, show full stack trace on error (Default: `False`)
3232
- **default_category**: if any command has been categorized, then all other commands that haven't been categorized will display under this section in the help output.
3333
- **default_error**: the error that prints when a non-existent command is run
34-
- **default_to_shell**: if `True`, attempt to run unrecognized commands as shell commands (Default: `False`)
3534
- **disabled_commands**: commands that have been disabled from use. This is to support commands that are only available during specific states of the application. This dictionary's keys are the command names and its values are DisabledCommand objects.
3635
- **doc_header**: Set the header used for the help function's listing of documented functions
3736
- **echo**: if `True`, each command the user issues will be repeated to the screen before it is executed. This is particularly useful when running scripts. This behavior does not occur when running a command at the prompt. (Default: `False`)

docs/features/misc.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,3 @@ See the definitions of these functions for descriptions of their arguments.
5454
See the `do_enable_commands()` and `do_disable_commands()` functions in the
5555
[help_categories.py](https://github.com/python-cmd2/cmd2/blob/main/examples/help_categories.py)
5656
example for a demonstration.
57-
58-
## Default to shell
59-
60-
Every `cmd2` application can execute operating-system level (shell) commands with `shell` or a `!`
61-
shortcut:
62-
63-
(Cmd) shell which python
64-
/usr/bin/python
65-
(Cmd) !which python
66-
/usr/bin/python
67-
68-
However, if the parameter `default_to_shell` is `True`, then _every_ thing entered which doesn't
69-
match another command will be attempted on the operating system. Only if that attempt fails (i.e.,
70-
produces a nonzero return value) will the application's own `default` method be called.
71-
72-
(Cmd) which python
73-
/usr/bin/python
74-
(Cmd) my dog has fleas
75-
sh: my: not found
76-
*** Unknown syntax: my dog has fleas

examples/cmd_as_argument.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
class CmdLineApp(cmd2.Cmd):
1717
"""Example cmd2 application."""
1818

19-
# Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist
20-
# default_to_shell = True # noqa: ERA001
2119
MUMBLES = ('like', '...', 'um', 'er', 'hmmm', 'ahh')
2220
MUMBLE_FIRST = ('so', 'like', 'well')
2321
MUMBLE_LAST = ('right?',)

examples/hooks.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class CmdLineApp(cmd2.Cmd):
3737
3838
"""
3939

40-
# Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist
41-
# default_to_shell = True # noqa: ERA001
4240
def __init__(self, *args, **kwargs) -> None:
4341
super().__init__(*args, **kwargs)
4442

tests/test_cmd2.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,26 +1293,6 @@ def test_add_alert(base_app) -> None:
12931293
assert len(base_app._alert_queue) == orig_num_alerts + 3
12941294

12951295

1296-
class ShellApp(cmd2.Cmd):
1297-
def __init__(self, *args, **kwargs) -> None:
1298-
super().__init__(*args, **kwargs)
1299-
self.default_to_shell = True
1300-
1301-
1302-
def test_default_to_shell(base_app, monkeypatch) -> None:
1303-
if sys.platform.startswith('win'):
1304-
line = 'dir'
1305-
else:
1306-
line = 'ls'
1307-
1308-
base_app.default_to_shell = True
1309-
m = mock.Mock()
1310-
monkeypatch.setattr("{}.Popen".format('subprocess'), m)
1311-
out, _err = run_cmd(base_app, line)
1312-
assert out == []
1313-
assert m.called
1314-
1315-
13161296
def test_visible_prompt() -> None:
13171297
app = cmd2.Cmd()
13181298

tests/test_completion.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -484,29 +484,6 @@ def test_path_completion_nomatch(cmd2_app, request) -> None:
484484
assert not completions
485485

486486

487-
def test_default_to_shell_completion(cmd2_app, request) -> None:
488-
cmd2_app.default_to_shell = True
489-
test_dir = os.path.dirname(request.module.__file__)
490-
491-
text = os.path.join(test_dir, 'conftest')
492-
493-
if sys.platform == "win32":
494-
command = 'calc.exe'
495-
else:
496-
command = 'egrep'
497-
498-
# Make sure the command is on the testing system
499-
assert command in utils.get_exes_in_path(command)
500-
line = f'{command} {text}'
501-
502-
endidx = len(line)
503-
begidx = endidx - len(text)
504-
505-
expected = [text + '.py']
506-
completions = cmd2_app.complete(text, line, begidx, endidx)
507-
assert completions.to_strings() == Completions.from_values(expected).to_strings()
508-
509-
510487
def test_path_completion_no_text(cmd2_app) -> None:
511488
# Run path complete with no search text which should show what's in cwd
512489
text = ''

0 commit comments

Comments
 (0)