Skip to content

Commit ed92d58

Browse files
authored
Updated getting_started.py example to remove multi-line command usage (#1713)
The rational here is that using multiline commands is not particularly common and only recommended for niche use cases.
1 parent e237946 commit ed92d58

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

examples/getting_started.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
44
Features demonstrated include all of the following:
55
1) Colorizing/stylizing output
6-
2) Using multiline commands
7-
3) Persistent history
8-
4) How to run an initialization script at startup
9-
5) How to group and categorize commands when displaying them in help
10-
6) Opting-in to using the ipy command to run an IPython shell
11-
7) Allowing access to your application in py and ipy
12-
8) Displaying an intro banner upon starting your application
13-
9) Using a custom prompt
14-
10) How to make custom attributes settable at runtime.
15-
11) Shortcuts for commands
16-
12) Persistent bottom toolbar with realtime status updates
17-
13) Right prompt which displays contextual information
18-
14) Background thread to update the content displayed by the bottom toolbar outside of the UI thread to keep things responsive
19-
15) Using preloop() and postloop() hooks to start and stop a background thread
20-
16) Using the with_annotated decorator to parse typed command arguments
21-
17) Using the with_argparser decorator to parse command arguments with a custom parser
6+
2) Persistent history
7+
3) How to run an initialization script at startup
8+
4) How to group and categorize commands when displaying them in help
9+
5) Opting-in to using the ipy command to run an IPython shell
10+
6) Allowing access to your application in py and ipy
11+
7) Displaying an intro banner upon starting your application
12+
8) Using a custom prompt
13+
9) How to make custom attributes settable at runtime
14+
10) Shortcuts for commands
15+
11) Persistent bottom toolbar with realtime status updates
16+
12) Right prompt which displays contextual information
17+
13) Background thread to update the content displayed by the bottom toolbar outside of the UI thread to keep things responsive
18+
14) Using preloop() and postloop() hooks to start and stop a background thread
19+
15) Using the with_annotated decorator to parse typed command arguments
20+
16) Using the with_argparser decorator to parse command arguments with a custom parser
2221
"""
2322

2423
import argparse
@@ -59,7 +58,6 @@ def __init__(self) -> None:
5958
enable_bottom_toolbar=True,
6059
enable_rprompt=True,
6160
include_ipy=True,
62-
multiline_commands=["echo"],
6361
persistent_history_file="cmd2_history.dat",
6462
refresh_interval=0.5, # refresh the UI twice a second to keep the bottom toolbar timestamp current
6563
shortcuts=shortcuts,
@@ -79,9 +77,6 @@ def __init__(self) -> None:
7977
# Show this as the prompt when asking for input
8078
self.prompt = "myapp> "
8179

82-
# Used as prompt for multiline commands after the first line
83-
self.continuation_prompt = "... "
84-
8580
# Allow access to your application in py and ipy via self
8681
self.self_in_py = True
8782

@@ -121,14 +116,12 @@ def _update_toolbar_state(self) -> None:
121116

122117
def preloop(self) -> None:
123118
"""Hook method executed once when the cmdloop() method is called."""
124-
super().preloop()
125119
self._stop_thread_event.clear()
126120
self._toolbar_thread = threading.Thread(target=self._update_toolbar_state, daemon=True)
127121
self._toolbar_thread.start()
128122

129123
def postloop(self) -> None:
130124
"""Hook method executed once when the cmdloop() method is about to return."""
131-
super().postloop()
132125
if self._toolbar_thread and self._toolbar_thread.is_alive():
133126
self._stop_thread_event.set()
134127
self._toolbar_thread.join()
@@ -201,15 +194,15 @@ def do_intro(self, _: cmd2.Statement) -> None:
201194
@staticmethod
202195
def _build_echo_parser() -> cmd2.Cmd2ArgumentParser:
203196
"""Parser factory method for use with the echo command."""
204-
echo_parser = cmd2.Cmd2ArgumentParser(description="Multiline command that echoes input.")
197+
echo_parser = cmd2.Cmd2ArgumentParser(description="Command that echoes input.")
205198
echo_parser.add_argument("-u", "--upper", action="store_true", help="uppercase the output")
206199
echo_parser.add_argument("-r", "--repeat", type=int, default=1, help="output [n] times")
207200
echo_parser.add_argument("words", nargs="+", help="words to print")
208201
return echo_parser
209202

210203
@cmd2.with_argparser(_build_echo_parser)
211204
def do_echo(self, args: argparse.Namespace) -> None:
212-
"""Multiline command."""
205+
"""Command using with_argparser decorator for parsing arguments."""
213206
output_str = " ".join(args.words)
214207
if args.upper:
215208
output_str = output_str.upper()

0 commit comments

Comments
 (0)