Skip to content

Commit 908e75a

Browse files
committed
Removed macros.
1 parent 0937472 commit 908e75a

23 files changed

+112
-928
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.0.0 (TBD)
2+
3+
- Breaking Change
4+
- Removed macros
5+
16
## 2.7.0 (June 30, 2025)
27

38
- Enhancements

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ first pillar of 'ease of command discovery'. The following is a list of features
6969

7070
<a href="https://imgflip.com/i/66t0y0"><img src="https://i.imgflip.com/66t0y0.jpg" title="made at imgflip.com" width="70%" height="70%"/></a>
7171

72-
cmd2 creates the second pillar of 'ease of transition to automation' through alias/macro creation,
73-
command line argument parsing and execution of cmd2 scripting.
72+
cmd2 creates the second pillar of 'ease of transition to automation' through alias creation, command
73+
line argument parsing and execution of cmd2 scripting.
7474

75-
- Flexible alias and macro creation for quick abstraction of commands.
75+
- Flexible alias creation for quick abstraction of commands.
7676
- Text file scripting of your application with `run_script` (`@`) and `_relative_run_script` (`@@`)
7777
- Powerful and flexible built-in Python scripting of your application using the `run_pyscript`
7878
command

cmd2/cmd2.py

Lines changed: 14 additions & 373 deletions
Large diffs are not rendered by default.

cmd2/parsing.py

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,6 @@ def shlex_split(str_to_split: str) -> list[str]:
3535
return shlex.split(str_to_split, comments=False, posix=False)
3636

3737

38-
@dataclass(frozen=True)
39-
class MacroArg:
40-
"""Information used to replace or unescape arguments in a macro value when the macro is resolved.
41-
42-
Normal argument syntax: {5}
43-
Escaped argument syntax: {{5}}.
44-
"""
45-
46-
# The starting index of this argument in the macro value
47-
start_index: int
48-
49-
# The number string that appears between the braces
50-
# This is a string instead of an int because we support unicode digits and must be able
51-
# to reproduce this string later
52-
number_str: str
53-
54-
# Tells if this argument is escaped and therefore needs to be unescaped
55-
is_escaped: bool
56-
57-
# Pattern used to find normal argument
58-
# Digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side
59-
# Match strings like: {5}, {{{{{4}, {2}}}}}
60-
macro_normal_arg_pattern = re.compile(r'(?<!{){\d+}|{\d+}(?!})')
61-
62-
# Pattern used to find escaped arguments
63-
# Digits surrounded by 2 or more braces on both sides
64-
# Match strings like: {{5}}, {{{{{4}}, {{2}}}}}
65-
macro_escaped_arg_pattern = re.compile(r'{{2}\d+}{2}')
66-
67-
# Finds a string of digits
68-
digit_pattern = re.compile(r'\d+')
69-
70-
71-
@dataclass(frozen=True)
72-
class Macro:
73-
"""Defines a cmd2 macro."""
74-
75-
# Name of the macro
76-
name: str
77-
78-
# The string the macro resolves to
79-
value: str
80-
81-
# The minimum number of args the user has to pass to this macro
82-
minimum_arg_count: int
83-
84-
# Used to fill in argument placeholders in the macro
85-
arg_list: list[MacroArg] = field(default_factory=list)
86-
87-
8838
@dataclass(frozen=True)
8939
class Statement(str): # type: ignore[override] # noqa: SLOT000
9040
"""String subclass with additional attributes to store the results of parsing.
@@ -205,10 +155,10 @@ def expanded_command_line(self) -> str:
205155
def argv(self) -> list[str]:
206156
"""A list of arguments a-la ``sys.argv``.
207157
208-
The first element of the list is the command after shortcut and macro
209-
expansion. Subsequent elements of the list contain any additional
210-
arguments, with quotes removed, just like bash would. This is very
211-
useful if you are going to use ``argparse.parse_args()``.
158+
The first element of the list is the command after shortcut expansion.
159+
Subsequent elements of the list contain any additional arguments,
160+
with quotes removed, just like bash would. This is very useful if
161+
you are going to use ``argparse.parse_args()``.
212162
213163
If you want to strip quotes from the input, you can use ``argv[1:]``.
214164
"""

docs/examples/first_app.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Here's a quick walkthrough of a simple application which demonstrates 8 features
77
- [Argument Processing](../features/argument_processing.md)
88
- [Generating Output](../features/generating_output.md)
99
- [Help](../features/help.md)
10-
- [Shortcuts](../features/shortcuts_aliases_macros.md#shortcuts)
10+
- [Shortcuts](../features/shortcuts_aliases.md#shortcuts)
1111
- [Multiline Commands](../features/multiline_commands.md)
1212
- [History](../features/history.md)
1313

@@ -166,7 +166,7 @@ With those few lines of code, we created a [command](../features/commands.md), u
166166
## Shortcuts
167167

168168
`cmd2` has several capabilities to simplify repetitive user input:
169-
[Shortcuts, Aliases, and Macros](../features/shortcuts_aliases_macros.md). Let's add a shortcut to
169+
[Shortcuts and Aliases](../features/shortcuts_aliases.md). Let's add a shortcut to
170170
our application. Shortcuts are character strings that can be used instead of a command name. For
171171
example, `cmd2` has support for a shortcut `!` which runs the `shell` command. So instead of typing
172172
this:

docs/features/builtin_commands.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ to be part of the application.
99
### alias
1010

1111
This command manages aliases via subcommands `create`, `delete`, and `list`. See
12-
[Aliases](shortcuts_aliases_macros.md#aliases) for more information.
12+
[Aliases](shortcuts_aliases.md#aliases) for more information.
1313

1414
### edit
1515

@@ -38,12 +38,6 @@ history. See [History](history.md) for more information.
3838
This optional opt-in command enters an interactive IPython shell. See
3939
[IPython (optional)](./embedded_python_shells.md#ipython-optional) for more information.
4040

41-
### macro
42-
43-
This command manages macros via subcommands `create`, `delete`, and `list`. A macro is similar to an
44-
alias, but it can contain argument placeholders. See [Macros](./shortcuts_aliases_macros.md#macros)
45-
for more information.
46-
4741
### py
4842

4943
This command invokes a Python command or shell. See
@@ -114,8 +108,8 @@ Execute a command as if at the operating system shell prompt:
114108

115109
### shortcuts
116110

117-
This command lists available shortcuts. See [Shortcuts](./shortcuts_aliases_macros.md#shortcuts) for
118-
more information.
111+
This command lists available shortcuts. See [Shortcuts](./shortcuts_aliases.md#shortcuts) for more
112+
information.
119113

120114
## Remove Builtin Commands
121115

docs/features/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ backwards compatibility.
6161
- quoted arguments
6262
- output redirection and piping
6363
- multi-line commands
64-
- shortcut, macro, and alias expansion
64+
- shortcut and alias expansion
6565

6666
In addition to parsing all of these elements from the user input, `cmd2` also has code to make all
6767
of these items work; it's almost transparent to you and to the commands you write in your own

docs/features/help.md

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ command. The `help` command by itself displays a list of the commands available:
1414
1515
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
1616
===========================================================================
17-
alias help ipy py run_pyscript set shortcuts
18-
edit history macro quit run_script shell
17+
alias help ipy quit run_script shell
18+
edit history py run_pyscript set shortcuts
1919
```
2020

2121
The `help` command can also be used to provide detailed help for a specific command:
@@ -53,8 +53,8 @@ By default, the `help` command displays:
5353

5454
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
5555
===========================================================================
56-
alias help ipy py run_pyscript set shortcuts
57-
edit history macro quit run_script shell
56+
alias help ipy quit run_script shell
57+
edit history py run_pyscript set shortcuts
5858

5959
If you have a large number of commands, you can optionally group your commands into categories.
6060
Here's the output from the example `help_categories.py`:
@@ -80,8 +80,8 @@ Here's the output from the example `help_categories.py`:
8080

8181
Other
8282
=====
83-
alias edit history py run_pyscript set shortcuts
84-
config help macro quit run_script shell version
83+
alias edit history run_pyscript set shortcuts
84+
config help quit run_script shell version
8585

8686
There are 2 methods of specifying command categories, using the `@with_category` decorator or with
8787
the `categorize()` function. Once a single command category is detected, the help output switches to
@@ -137,51 +137,54 @@ categories with per-command Help Messages:
137137
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
138138

139139
Application Management
140-
================================================================================
141-
deploy Deploy command
142-
expire Expire command
143-
findleakers Find Leakers command
144-
list List command
145-
redeploy Redeploy command
146-
restart usage: restart [-h] {now,later,sometime,whenever}
147-
sessions Sessions command
148-
start Start command
149-
stop Stop command
150-
undeploy Undeploy command
140+
======================================================================================================
141+
deploy Deploy command.
142+
expire Expire command.
143+
findleakers Find Leakers command.
144+
list List command.
145+
redeploy Redeploy command.
146+
restart Restart
147+
sessions Sessions command.
148+
start Start
149+
stop Stop command.
150+
undeploy Undeploy command.
151+
152+
Command Management
153+
======================================================================================================
154+
disable_commands Disable the Application Management commands.
155+
enable_commands Enable the Application Management commands.
151156

152157
Connecting
153-
================================================================================
154-
connect Connect command
155-
which Which command
158+
======================================================================================================
159+
connect Connect command.
160+
which Which command.
156161

157162
Server Information
158-
================================================================================
159-
resources Resources command
160-
serverinfo Server Info command
161-
sslconnectorciphers SSL Connector Ciphers command is an example of a command that contains
162-
multiple lines of help information for the user. Each line of help in a
163-
contiguous set of lines will be printed and aligned in the verbose output
164-
provided with 'help --verbose'
165-
status Status command
166-
thread_dump Thread Dump command
167-
vminfo VM Info command
163+
======================================================================================================
164+
resources Resources command.
165+
serverinfo Server Info command.
166+
sslconnectorciphers SSL Connector Ciphers command is an example of a command that contains
167+
multiple lines of help information for the user. Each line of help in a
168+
contiguous set of lines will be printed and aligned in the verbose output
169+
provided with 'help --verbose'.
170+
status Status command.
171+
thread_dump Thread Dump command.
172+
vminfo VM Info command.
168173

169174
Other
170-
================================================================================
171-
alias Manage aliases
172-
config Config command
173-
edit Run a text editor and optionally open a file with it
174-
help List available commands or provide detailed help for a specific command
175-
history View, run, edit, save, or clear previously entered commands
176-
macro Manage macros
177-
py Invoke Python command or shell
178-
quit Exits this application
179-
run_pyscript Runs a python script file inside the console
180-
run_script Runs commands in script file that is encoded as either ASCII or UTF-8 text
181-
set Set a settable parameter or show current settings of parameters
182-
shell Execute a command as if at the OS prompt
183-
shortcuts List available shortcuts
184-
version Version command
175+
======================================================================================================
176+
alias Manage aliases
177+
config Config command.
178+
edit Run a text editor and optionally open a file with it
179+
help List available commands or provide detailed help for a specific command
180+
history View, run, edit, save, or clear previously entered commands
181+
quit Exit this application
182+
run_pyscript Run a Python script file inside the console
183+
run_script Run commands in script file that is encoded as either ASCII or UTF-8 text
184+
set Set a settable parameter or show current settings of parameters.
185+
shell Execute a command as if at the OS prompt
186+
shortcuts List available shortcuts
187+
version Version command.
185188

186189
When called with the `-v` flag for verbose help, the one-line description for each command is
187190
provided by the first line of the docstring for that command's associated `do_*` method.

docs/features/history.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ without line numbers, so you can copy them to the clipboard:
198198

199199
(Cmd) history -s 1:3
200200

201-
`cmd2` supports both aliases and macros, which allow you to substitute a short, more convenient
202-
input string with a longer replacement string. Say we create an alias like this, and then use it:
201+
`cmd2` supports aliases which allow you to substitute a short, more convenient input string with a
202+
longer replacement string. Say we create an alias like this, and then use it:
203203

204204
(Cmd) alias create ls shell ls -aF
205205
Alias 'ls' created
@@ -212,7 +212,7 @@ By default, the `history` command shows exactly what we typed:
212212
1 alias create ls shell ls -aF
213213
2 ls -d h*
214214

215-
There are two ways to modify that display so you can see what aliases and macros were expanded to.
215+
There are two ways to modify the display so you can see what aliases and shortcuts were expanded to.
216216
The first is to use `-x` or `--expanded`. These options show the expanded command instead of the
217217
entered command:
218218

@@ -229,5 +229,5 @@ option:
229229
2x shell ls -aF -d h*
230230

231231
If the entered command had no expansion, it is displayed as usual. However, if there is some change
232-
as the result of expanding macros and aliases, then the entered command is displayed with the
233-
number, and the expanded command is displayed with the number followed by an `x`.
232+
as the result of expanding aliases, then the entered command is displayed with the number, and the
233+
expanded command is displayed with the number followed by an `x`.

docs/features/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [Output Redirection and Pipes](redirection.md)
2525
- [Scripting](scripting.md)
2626
- [Settings](settings.md)
27-
- [Shortcuts, Aliases, and Macros](shortcuts_aliases_macros.md)
27+
- [Shortcuts and Aliases](shortcuts_aliases.md)
2828
- [Startup Commands](startup_commands.md)
2929
- [Table Creation](table_creation.md)
3030
- [Transcripts](transcripts.md)

docs/features/initialization.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The `cmd2.Cmd` class provides a large number of public instance attributes which
9292

9393
### Public instance attributes
9494

95-
Here are instance attributes of `cmd2.Cmd` which developers might wish override:
95+
Here are instance attributes of `cmd2.Cmd` which developers might wish to override:
9696

9797
- **always_show_hint**: if `True`, display tab completion hint even when completion suggestions print (Default: `False`)
9898
- **broken_pipe_warning**: if non-empty, this string will be displayed if a broken pipe error occurs
@@ -112,7 +112,6 @@ Here are instance attributes of `cmd2.Cmd` which developers might wish override:
112112
- **help_error**: the error that prints when no help information can be found
113113
- **hidden_commands**: commands to exclude from the help menu and tab completion
114114
- **last_result**: stores results from the last command run to enable usage of results in a Python script or interactive console. Built-in commands don't make use of this. It is purely there for user-defined commands and convenience.
115-
- **macros**: dictionary of macro names and their values
116115
- **max_completion_items**: max number of CompletionItems to display during tab completion (Default: 50)
117116
- **pager**: sets the pager command used by the `Cmd.ppaged()` method for displaying wrapped output using a pager
118117
- **pager_chop**: sets the pager command used by the `Cmd.ppaged()` method for displaying chopped/truncated output using a pager

docs/features/os.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ See [Output Redirection and Pipes](./redirection.md#output-redirection-and-pipes
1010

1111
(Cmd) shell ls -al
1212

13-
If you use the default [Shortcuts](./shortcuts_aliases_macros.md#shortcuts) defined in `cmd2` you'll
14-
get a `!` shortcut for `shell`, which allows you to type:
13+
If you use the default [Shortcuts](./shortcuts_aliases.md#shortcuts) defined in `cmd2` you'll get a
14+
`!` shortcut for `shell`, which allows you to type:
1515

1616
(Cmd) !ls -al
1717

@@ -89,8 +89,8 @@ shell, and execute those commands before entering the command loop:
8989

9090
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
9191
===========================================================================
92-
alias help macro orate quit run_script set shortcuts
93-
edit history mumble py run_pyscript say shell speak
92+
alias help ipy quit run_script shell
93+
edit history py run_pyscript set shortcuts
9494

9595
(Cmd)
9696

0 commit comments

Comments
 (0)