Skip to content

Commit d3030b8

Browse files
authored
Merge branch 'main' into settable
2 parents aef92ce + ed92d58 commit d3030b8

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
@@ -60,7 +59,6 @@ def __init__(self) -> None:
6059
enable_bottom_toolbar=True,
6160
enable_rprompt=True,
6261
include_ipy=True,
63-
multiline_commands=["echo"],
6462
persistent_history_file="cmd2_history.dat",
6563
refresh_interval=0.5, # refresh the UI twice a second to keep the bottom toolbar timestamp current
6664
shortcuts=shortcuts,
@@ -80,9 +78,6 @@ def __init__(self) -> None:
8078
# Show this as the prompt when asking for input
8179
self.prompt = "myapp> "
8280

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

@@ -131,14 +126,12 @@ def _update_toolbar_state(self) -> None:
131126

132127
def preloop(self) -> None:
133128
"""Hook method executed once when the cmdloop() method is called."""
134-
super().preloop()
135129
self._stop_thread_event.clear()
136130
self._toolbar_thread = threading.Thread(target=self._update_toolbar_state, daemon=True)
137131
self._toolbar_thread.start()
138132

139133
def postloop(self) -> None:
140134
"""Hook method executed once when the cmdloop() method is about to return."""
141-
super().postloop()
142135
if self._toolbar_thread and self._toolbar_thread.is_alive():
143136
self._stop_thread_event.set()
144137
self._toolbar_thread.join()
@@ -211,15 +204,15 @@ def do_intro(self, _: cmd2.Statement) -> None:
211204
@staticmethod
212205
def _build_echo_parser() -> cmd2.Cmd2ArgumentParser:
213206
"""Parser factory method for use with the echo command."""
214-
echo_parser = cmd2.Cmd2ArgumentParser(description="Multiline command that echoes input.")
207+
echo_parser = cmd2.Cmd2ArgumentParser(description="Command that echoes input.")
215208
echo_parser.add_argument("-u", "--upper", action="store_true", help="uppercase the output")
216209
echo_parser.add_argument("-r", "--repeat", type=int, default=1, help="output [n] times")
217210
echo_parser.add_argument("words", nargs="+", help="words to print")
218211
return echo_parser
219212

220213
@cmd2.with_argparser(_build_echo_parser)
221214
def do_echo(self, args: argparse.Namespace) -> None:
222-
"""Multiline command."""
215+
"""Command using with_argparser decorator for parsing arguments."""
223216
output_str = " ".join(args.words)
224217
if args.upper:
225218
output_str = output_str.upper()

0 commit comments

Comments
 (0)