Skip to content

Commit eecd1c5

Browse files
committed
Merged master into history branch and fixed merge conflicts
2 parents a3511a6 + 7b1b8b1 commit eecd1c5

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
## 0.9.9 (TBD, 2019)
1+
## 0.9.10 (February 22, 2019)
2+
* Bug Fixes
3+
* Fixed unit test that hangs on Windows
4+
5+
## 0.9.9 (February 21, 2019)
26
* Bug Fixes
37
* Fixed bug where the ``set`` command was not tab completing from the current ``settable`` dictionary.
8+
* Enhancements
9+
* Changed edit command to use do_shell() instead of calling os.system()
410

511
## 0.9.8 (February 06, 2019)
612
* Bug Fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Main Features
3131
- Multi-line commands
3232
- Special-character command shortcuts (beyond cmd's `?` and `!`)
3333
- Command aliasing similar to bash `alias` command
34-
- Macros, which are similar to aliases, but can take arguments when called
34+
- Macros, which are similar to aliases, but they can contain argument placeholders
3535
- Ability to load commands at startup from an initialization script
3636
- Settable environment parameters
3737
- Parsing commands with arguments using `argparse`, including support for sub-commands

cmd2/cmd2.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ def macro_list(self, args: argparse.Namespace) -> None:
24082408
# Top-level parser for macro
24092409
macro_description = ("Manage macros\n"
24102410
"\n"
2411-
"A macro is similar to an alias, but it can take arguments when called.")
2411+
"A macro is similar to an alias, but it can contain argument placeholders.")
24122412
macro_epilog = ("See also:\n"
24132413
" alias")
24142414
macro_parser = ACArgumentParser(description=macro_description, epilog=macro_epilog, prog='macro')
@@ -2420,7 +2420,7 @@ def macro_list(self, args: argparse.Namespace) -> None:
24202420
macro_create_help = "create or overwrite a macro"
24212421
macro_create_description = "Create or overwrite a macro"
24222422

2423-
macro_create_epilog = ("A macro is similar to an alias, but it can take arguments when called.\n"
2423+
macro_create_epilog = ("A macro is similar to an alias, but it can contain argument placeholders.\n"
24242424
"Arguments are expressed when creating a macro using {#} notation where {1}\n"
24252425
"means the first argument.\n"
24262426
"\n"
@@ -3247,7 +3247,7 @@ def do_history(self, args: argparse.Namespace) -> None:
32473247
for command in history:
32483248
fobj.write('{}\n'.format(command))
32493249
try:
3250-
os.system('"{}" "{}"'.format(self.editor, fname))
3250+
self.do_edit(fname)
32513251
self.do_load(fname)
32523252
except Exception:
32533253
raise
@@ -3352,12 +3352,11 @@ def do_edit(self, args: argparse.Namespace) -> None:
33523352
if not self.editor:
33533353
raise EnvironmentError("Please use 'set editor' to specify your text editing program of choice.")
33543354

3355-
editor = utils.quote_string_if_needed(self.editor)
3355+
command = utils.quote_string_if_needed(os.path.expanduser(self.editor))
33563356
if args.file_path:
3357-
expanded_path = utils.quote_string_if_needed(os.path.expanduser(args.file_path))
3358-
os.system('{} {}'.format(editor, expanded_path))
3359-
else:
3360-
os.system('{}'.format(editor))
3357+
command += " " + utils.quote_string_if_needed(os.path.expanduser(args.file_path))
3358+
3359+
self.do_shell(command)
33613360

33623361
@property
33633362
def _current_script_dir(self) -> Optional[str]:

docs/settingchanges.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ Macros
7575
======
7676

7777
``cmd2`` provides a feature that is similar to aliases called macros. The major difference between macros and aliases
78-
is that macros are intended to take arguments when called. These can be useful if you need to run a complex command
79-
frequently with different arguments that appear in various parts of the command.
80-
81-
Arguments are expressed when creating a macro using {#} notation where {1} means the first argument.
78+
is that macros can contain argument placeholders. Arguments are expressed when creating a macro using {#} notation
79+
where {1} means the first argument.
8280

8381
The following creates a macro called my_macro that expects two arguments:
8482

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- Multi-line commands
2929
- Special-character command shortcuts (beyond cmd's `?` and `!`)
3030
- Command aliasing similar to bash `alias` command
31-
- Macros, which are similar to aliases, but can take arguments when called
31+
- Macros, which are similar to aliases, but they can contain argument placeholders
3232
- Ability to load commands at startup from an initialization script
3333
- Settable environment parameters
3434
- Parsing commands with arguments using `argparse`, including support for sub-commands

tests/test_cmd2.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -678,47 +678,45 @@ def test_edit_file(base_app, request, monkeypatch):
678678
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
679679
base_app.editor = 'fooedit'
680680

681-
# Mock out the os.system call so we don't actually open an editor
682-
m = mock.MagicMock(name='system')
683-
monkeypatch.setattr("os.system", m)
681+
# Mock out the subprocess.Popen call so we don't actually open an editor
682+
m = mock.MagicMock(name='Popen')
683+
monkeypatch.setattr("subprocess.Popen", m)
684684

685685
test_dir = os.path.dirname(request.module.__file__)
686686
filename = os.path.join(test_dir, 'script.txt')
687687

688688
run_cmd(base_app, 'edit {}'.format(filename))
689689

690-
# We think we have an editor, so should expect a system call
691-
m.assert_called_once_with('{} {}'.format(utils.quote_string_if_needed(base_app.editor),
692-
utils.quote_string_if_needed(filename)))
690+
# We think we have an editor, so should expect a Popen call
691+
m.assert_called_once()
693692

694693
def test_edit_file_with_spaces(base_app, request, monkeypatch):
695694
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
696695
base_app.editor = 'fooedit'
697696

698-
# Mock out the os.system call so we don't actually open an editor
699-
m = mock.MagicMock(name='system')
700-
monkeypatch.setattr("os.system", m)
697+
# Mock out the subprocess.Popen call so we don't actually open an editor
698+
m = mock.MagicMock(name='Popen')
699+
monkeypatch.setattr("subprocess.Popen", m)
701700

702701
test_dir = os.path.dirname(request.module.__file__)
703702
filename = os.path.join(test_dir, 'my commands.txt')
704703

705704
run_cmd(base_app, 'edit "{}"'.format(filename))
706705

707-
# We think we have an editor, so should expect a system call
708-
m.assert_called_once_with('{} {}'.format(utils.quote_string_if_needed(base_app.editor),
709-
utils.quote_string_if_needed(filename)))
706+
# We think we have an editor, so should expect a Popen call
707+
m.assert_called_once()
710708

711709
def test_edit_blank(base_app, monkeypatch):
712710
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
713711
base_app.editor = 'fooedit'
714712

715-
# Mock out the os.system call so we don't actually open an editor
716-
m = mock.MagicMock(name='system')
717-
monkeypatch.setattr("os.system", m)
713+
# Mock out the subprocess.Popen call so we don't actually open an editor
714+
m = mock.MagicMock(name='Popen')
715+
monkeypatch.setattr("subprocess.Popen", m)
718716

719717
run_cmd(base_app, 'edit')
720718

721-
# We have an editor, so should expect a system call
719+
# We have an editor, so should expect a Popen call
722720
m.assert_called_once()
723721

724722

tests/test_history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def test_history_edit(base_app, monkeypatch):
221221
base_app.editor = 'fooedit'
222222

223223
# Mock out the os.system call so we don't actually open an editor
224-
m = mock.MagicMock(name='system')
225-
monkeypatch.setattr("os.system", m)
224+
m = mock.MagicMock(name='Popen')
225+
monkeypatch.setattr("subprocess.Popen", m)
226226

227227
# Run help command just so we have a command in history
228228
run_cmd(base_app, 'help')

0 commit comments

Comments
 (0)