Skip to content

Commit 28f226a

Browse files
authored
Update help text and documentation for history -t argument (#1440)
* Update help text and documentation for history -t argument Clarified that this actually re-runs the select commands since the expected output from the commands isn't saved in the history along with the commands themselves. * Update 2.6.0 release date in preparation for a release * Fixed unit test * Fix self.last_resort typo
1 parent 493a4c8 commit 28f226a

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## 2.6.0 (May TBD, 2025)
1+
## 2.6.0 (May 31, 2025)
22

33
- Breaking Change
44
- `cmd2` 2.6 supports Python 3.9+ (removed support for Python 3.8)
55
- Enhancements
6-
- Add support for Python 3.14
6+
- Added support for Python 3.14
77
- Added new `Cmd.ppretty()` method for pretty printing arbitrary Python data structures
8+
- Clarified help text for `-t`/`--transcript` argument to the `history` command
89

910
## 2.5.11 (January 25, 2025)
1011

cmd2/cmd2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,7 +4502,7 @@ def do_py(self, _: argparse.Namespace) -> Optional[bool]:
45024502
45034503
:return: True if running of commands should stop.
45044504
"""
4505-
# self.last_resort will be set by _run_python()
4505+
# self.last_result will be set by _run_python()
45064506
return self._run_python()
45074507

45084508
run_pyscript_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description="Run a Python script file inside the console")
@@ -4537,7 +4537,7 @@ def do_run_pyscript(self, args: argparse.Namespace) -> Optional[bool]:
45374537
# Overwrite sys.argv to allow the script to take command line arguments
45384538
sys.argv = [args.script_path, *args.script_arguments]
45394539

4540-
# self.last_resort will be set by _run_python()
4540+
# self.last_result will be set by _run_python()
45414541
py_return = self._run_python(pyscript=args.script_path)
45424542
finally:
45434543
# Restore command line arguments to original state
@@ -4632,7 +4632,7 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover
46324632
'-t',
46334633
'--transcript',
46344634
metavar='TRANSCRIPT_FILE',
4635-
help='output commands and results to a transcript file,\nimplies -s',
4635+
help='create a transcript file by re-running the commands,\nimplies both -r and -s',
46364636
completer=path_complete,
46374637
)
46384638
history_action_group.add_argument('-c', '--clear', action='store_true', help='clear all history')
@@ -4730,7 +4730,7 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
47304730
try:
47314731
self.run_editor(fname)
47324732

4733-
# self.last_resort will be set by do_run_script()
4733+
# self.last_result will be set by do_run_script()
47344734
return self.do_run_script(utils.quote_string(fname))
47354735
finally:
47364736
os.remove(fname)
@@ -4750,7 +4750,7 @@ def do_history(self, args: argparse.Namespace) -> Optional[bool]:
47504750
self.pfeedback(f"{len(history)} command{plural} saved to {full_path}")
47514751
self.last_result = True
47524752
elif args.transcript:
4753-
# self.last_resort will be set by _generate_transcript()
4753+
# self.last_result will be set by _generate_transcript()
47544754
self._generate_transcript(list(history.values()), args.transcript)
47554755
else:
47564756
# Display the history items retrieved
@@ -5093,7 +5093,7 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
50935093
self._script_dir.append(os.path.dirname(expanded_path))
50945094

50955095
if args.transcript:
5096-
# self.last_resort will be set by _generate_transcript()
5096+
# self.last_result will be set by _generate_transcript()
50975097
self._generate_transcript(
50985098
script_commands,
50995099
os.path.expanduser(args.transcript),

docs/features/history.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ The `history` command can also save both the commands and their output to a text
127127

128128
The `--transcript` option implies `--run`: the commands must be re-run in order to capture their output to the transcript file.
129129

130+
!!! warning
131+
132+
Unlike the `-o`/`--output-file` option, the `-t`/`--transcript` option will actually run the selected history commands again. This is necessary for creating a transcript file since the history saves the commands themselves but does not save their output. Please note that a side-effect of this is that the commands will appear again at the end of the history.
133+
130134
The last action the history command can perform is to clear the command history using `-c` or `--clear`:
131135

132136
(Cmd) history -c

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def verify_help_text(
6565
-o, --output_file FILE
6666
output commands to a script file, implies -s
6767
-t, --transcript TRANSCRIPT_FILE
68-
output commands and results to a transcript file,
69-
implies -s
68+
create a transcript file by re-running the commands,
69+
implies both -r and -s
7070
-c, --clear clear all history
7171
7272
formatting:

0 commit comments

Comments
 (0)