Skip to content

Commit 88501ef

Browse files
committed
Fix initialization.py example so it uses a valid startup script and delete redundant alias_startup.py example
1 parent 829c7b9 commit 88501ef

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

docs/features/startup_commands.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class StartupApp(cmd2.Cmd):
4747
```
4848

4949
This text file should contain a [Command Script](./scripting.md#command-scripts). See the
50-
[AliasStartup](https://github.com/python-cmd2/cmd2/blob/main/examples/alias_startup.py) example for
51-
a demonstration.
50+
[initialization](https://github.com/python-cmd2/cmd2/blob/main/examples/initialization.py) example
51+
for a demonstration.
5252

5353
You can silence a startup script's output by setting `silence_startup_script` to True:
5454

examples/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ application, if you are looking for that then see
1111
Here is the list of examples in alphabetical order by filename along with a brief description of
1212
each:
1313

14-
- [alias_startup.py](https://github.com/python-cmd2/cmd2/blob/main/examples/alias_startup.py)
15-
- Demonstrates how to add custom command aliases and how to run an initialization script at
16-
startup
1714
- [arg_decorators.py](https://github.com/python-cmd2/cmd2/blob/main/examples/arg_decorators.py)
1815
- Demonstrates how to use the `cmd2.with_argparser` decorator to specify command arguments using
1916
[argparse](https://docs.python.org/3/library/argparse.html)
@@ -62,7 +59,7 @@ each:
6259
- [hooks.py](https://github.com/python-cmd2/cmd2/blob/main/examples/hooks.py)
6360
- Shows how to use various `cmd2` application lifecycle hooks
6461
- [initialization.py](https://github.com/python-cmd2/cmd2/blob/main/examples/initialization.py)
65-
- Shows how to colorize output, use multiline command, add persistent history, and more
62+
- Shows how to colorize output, use multiline command, add persistent history, and much more
6663
- [migrating.py](https://github.com/python-cmd2/cmd2/blob/main/examples/migrating.py)
6764
- A simple `cmd` application that you can migrate to `cmd2` by changing one line
6865
- [modular_commands_basic.py](https://github.com/python-cmd2/cmd2/blob/main/examples/modular_commands_basic.py)

examples/alias_startup.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/initialization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
10) How to make custom attributes settable at runtime.
1313
"""
1414

15+
import pathlib
16+
1517
from rich.style import Style
1618

1719
import cmd2
@@ -25,10 +27,13 @@ class BasicApp(cmd2.Cmd):
2527
CUSTOM_CATEGORY = 'My Custom Commands'
2628

2729
def __init__(self) -> None:
30+
# Startup script that defines a couple aliases for running shell commands
31+
alias_script = pathlib.Path(__file__).absolute().parent / '.cmd2rc'
32+
2833
super().__init__(
2934
multiline_commands=['echo'],
3035
persistent_history_file='cmd2_history.dat',
31-
startup_script='scripts/startup.txt',
36+
startup_script=alias_script,
3237
include_ipy=True,
3338
)
3439

0 commit comments

Comments
 (0)