Skip to content

Commit 41a49ff

Browse files
committed
Removed macros.
1 parent 285d959 commit 41a49ff

24 files changed

+107
-943
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0 (TBD)
2+
* Breaking Change
3+
* Removed macros
4+
15
## 2.5.0 (October 23, 2024)
26
* Breaking Change
37
* `cmd2` 2.5 supports Python 3.8+ (removed support for Python 3.6 and 3.7)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Deep extensive tab completion and help text generation based on the argparse lib
6262

6363
<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>
6464

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

67-
- Flexible alias and macro creation for quick abstraction of commands.
67+
- Flexible alias creation for quick abstraction of commands.
6868
- Text file scripting of your application with `run_script` (`@`) and `_relative_run_script` (`@@`)
6969
- Powerful and flexible built-in Python scripting of your application using the `run_pyscript` command
7070
- Transcripts for use with built-in regression can be automatically generated from `history -t` or `run_script -t`

cmd2/cmd2.py

Lines changed: 14 additions & 380 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
@@ -38,56 +38,6 @@ def shlex_split(str_to_split: str) -> List[str]:
3838
return shlex.split(str_to_split, comments=False, posix=False)
3939

4040

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

docs/api/cmd.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmd2.Cmd
99
.. attribute:: default_error
1010

1111
The error message displayed when a non-existent command is run.
12-
Default: ``{} is not a recognized command, alias, or macro.``
12+
Default: ``{} is not a recognized command or alias.``
1313

1414
.. attribute:: help_error
1515

docs/api/parsing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Classes for parsing and storing user input.
1515

1616
.. attribute:: command
1717

18-
The name of the command after shortcuts and macros have been expanded
18+
The name of the command after shortcuts have been expanded
1919

2020
.. attribute:: args
2121

docs/examples/first_app.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ features of ``cmd2``:
1111
* :ref:`features/argument_processing:Argument Processing`
1212
* :ref:`features/generating_output:Generating Output`
1313
* :ref:`features/help:Help`
14-
* :ref:`features/shortcuts_aliases_macros:Shortcuts`
14+
* :ref:`features/shortcuts_aliases:Shortcuts`
1515
* :ref:`features/multiline_commands:Multiline Commands`
1616
* :ref:`features/history:History`
1717

@@ -178,8 +178,8 @@ Shortcuts
178178
---------
179179

180180
``cmd2`` has several capabilities to simplify repetitive user input:
181-
:ref:`Shortcuts, Aliases, and Macros
182-
<features/shortcuts_aliases_macros:Shortcuts, Aliases, and Macros>`. Let's add
181+
:ref:`Shortcuts and Aliases
182+
<features/shortcuts_aliases:Shortcuts and Aliases>`. Let's add
183183
a shortcut to our application. Shortcuts are character strings that can be used
184184
instead of a command name. For example, ``cmd2`` has support for a shortcut
185185
``!`` which runs the ``shell`` command. So instead of typing this:

docs/features/builtin_commands.rst

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ alias
1313
~~~~~
1414

1515
This command manages aliases via subcommands ``create``, ``delete``, and
16-
``list``. See :ref:`features/shortcuts_aliases_macros:Aliases` for more
16+
``list``. See :ref:`features/shortcuts_aliases:Aliases` for more
1717
information.
1818

1919
edit
@@ -50,14 +50,6 @@ ipy
5050
This optional opt-in command enters an interactive IPython shell. See
5151
:ref:`features/embedded_python_shells:IPython (optional)` for more information.
5252

53-
macro
54-
~~~~~
55-
56-
This command manages macros via subcommands ``create``, ``delete``, and
57-
``list``. A macro is similar to an alias, but it can contain argument
58-
placeholders. See :ref:`features/shortcuts_aliases_macros:Macros` for more
59-
information.
60-
6153
py
6254
~~
6355

@@ -143,7 +135,7 @@ shortcuts
143135
~~~~~~~~~
144136

145137
This command lists available shortcuts. See
146-
:ref:`features/shortcuts_aliases_macros:Shortcuts` for more information.
138+
:ref:`features/shortcuts_aliases:Shortcuts` for more information.
147139

148140

149141
Remove Builtin Commands

docs/features/commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ the cmd_ module. This parsing handles:
6767
- quoted arguments
6868
- output redirection and piping
6969
- multi-line commands
70-
- shortcut, macro, and alias expansion
70+
- shortcut and alias expansion
7171

7272
In addition to parsing all of these elements from the user input, ``cmd2`` also
7373
has code to make all of these items work; it's almost transparent to you and to

docs/features/help.rst

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ of the commands available:
1919
2020
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
2121
===========================================================================
22-
alias help ipy py run_pyscript set shortcuts
23-
edit history macro quit run_script shell
22+
alias help ipy quit run_script shell
23+
edit history py run_pyscript set shortcuts
2424
2525
The ``help`` command can also be used to provide detailed help for a specific
2626
command:
@@ -63,8 +63,8 @@ By default, the ``help`` command displays::
6363

6464
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
6565
===========================================================================
66-
alias help ipy py run_pyscript set shortcuts
67-
edit history macro quit run_script shell
66+
alias help ipy quit run_script shell
67+
edit history py run_pyscript set shortcuts
6868

6969
If you have a large number of commands, you can optionally group your commands
7070
into categories. Here's the output from the example ``help_categories.py``::
@@ -90,8 +90,8 @@ into categories. Here's the output from the example ``help_categories.py``::
9090

9191
Other
9292
=====
93-
alias edit history py run_pyscript set shortcuts
94-
config help macro quit run_script shell version
93+
alias edit history run_pyscript set shortcuts
94+
config help quit run_script shell version
9595

9696
There are 2 methods of specifying command categories, using the
9797
``@with_category`` decorator or with the ``categorize()`` function. Once a
@@ -142,51 +142,49 @@ The ``help`` command also has a verbose option (``help -v`` or ``help
142142
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
143143

144144
Application Management
145-
================================================================================
146-
deploy Deploy command
147-
expire Expire command
148-
findleakers Find Leakers command
149-
list List command
150-
redeploy Redeploy command
151-
restart usage: restart [-h] {now,later,sometime,whenever}
152-
sessions Sessions command
153-
start Start command
154-
stop Stop command
155-
undeploy Undeploy command
145+
======================================================================================================
146+
deploy Deploy command
147+
expire Expire command
148+
findleakers Find Leakers command
149+
list List command
150+
redeploy Redeploy command
151+
restart Restart command
152+
sessions Sessions command
153+
start Start command
154+
stop Stop command
155+
undeploy Undeploy command
156156

157157
Connecting
158-
================================================================================
159-
connect Connect command
160-
which Which command
158+
======================================================================================================
159+
connect Connect command
160+
which Which command
161161

162162
Server Information
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
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
173173

174174
Other
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-
macro Manage macros
182-
py Invoke Python command or shell
183-
quit Exits this application
184-
run_pyscript Runs a python script file inside the console
185-
run_script Runs commands in script file that is encoded as either ASCII or UTF-8 text
186-
set Set a settable parameter or show current settings of parameters
187-
shell Execute a command as if at the OS prompt
188-
shortcuts List available shortcuts
189-
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
190188

191189
When called with the ``-v`` flag for verbose help, the one-line description for
192190
each command is provided by the first line of the docstring for that command's

docs/features/history.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ clipboard::
232232

233233
(Cmd) history -s 1:3
234234

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

239239
(Cmd) alias create ls shell ls -aF
240240
Alias 'ls' created
@@ -248,7 +248,7 @@ By default, the ``history`` command shows exactly what we typed::
248248
2 ls -d h*
249249

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

254254
(Cmd) history -x
@@ -264,6 +264,6 @@ If you want to see both the entered command and the expanded command, use the
264264
2x shell ls -aF -d h*
265265

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

docs/features/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Features
2626
redirection
2727
scripting
2828
settings
29-
shortcuts_aliases_macros
29+
shortcuts_aliases
3030
startup_commands
3131
table_creation
3232
transcripts

docs/features/initialization.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ override:
141141
of results in a Python script or interactive console. Built-in commands don't
142142
make use of this. It is purely there for user-defined commands and
143143
convenience.
144-
- **macros**: dictionary of macro names and their values
145144
- **max_completion_items**: max number of CompletionItems to display during
146145
tab completion (Default: 50)
147146
- **pager**: sets the pager command used by the ``Cmd.ppaged()`` method for

docs/features/os.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ operating system shell::
1414

1515
(Cmd) shell ls -al
1616

17-
If you use the default :ref:`features/shortcuts_aliases_macros:Shortcuts`
17+
If you use the default :ref:`features/shortcuts_aliases:Shortcuts`
1818
defined in ``cmd2`` you'll get a ``!`` shortcut for ``shell``, which allows you
1919
to type::
2020

@@ -107,8 +107,8 @@ loop::
107107

108108
Documented commands (use 'help -v' for verbose/'help <topic>' for details):
109109
===========================================================================
110-
alias help macro orate quit run_script set shortcuts
111-
edit history mumble py run_pyscript say shell speak
110+
alias help ipy quit run_script shell
111+
edit history py run_pyscript set shortcuts
112112

113113
(Cmd)
114114

0 commit comments

Comments
 (0)