Debian Codegraph @

docs/features/builtin_commands.md

raw symbols SCIP
1 # Builtin Commands
2
3 Applications which subclass [cmd2.Cmd][] inherit a number of commands which may be useful to your
4 users. Developers can [Remove Builtin Commands](#remove-builtin-commands) if they do not want them
5 to be part of the application.
6
7 ## List of Builtin Commands
8
9 ### alias
10
11 This command manages aliases via subcommands `create`, `delete`, and `list`. See
12 [Aliases](shortcuts_aliases_macros.md#aliases) for more information.
13
14 ### edit
15
16 This command launches an editor program and instructs it to open the given file name. Here's an
17 example:
18
19 ```sh
20 (Cmd) edit ~/.ssh/config
21 ```
22
23 The program to be launched is determined by the value of the [editor](settings.md#editor) setting.
24
25 ### help
26
27 This command lists available commands or provides detailed help for a specific command. When called
28 with the `-v/--verbose` argument, it shows a brief description of each command. See [Help](help.md)
29 for more information.
30
31 ### history
32
33 This command allows you to view, run, edit, save, or clear previously entered commands from the
34 history. See [History](history.md) for more information.
35
36 ### ipy (optional)
37
38 This optional opt-in command enters an interactive :simple-jupyter: IPython shell. See
39 [IPython (optional)](./embedded_python_shells.md#ipython-optional) for more information.
40
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
47 ### py (optional)
48
49 This optional opt-in command invokes a Python command or shell. See
50 [Embedded Python Shells](./embedded_python_shells.md) for more information.
51
52 ### quit
53
54 This command exits the `cmd2` application.
55
56 ### run_pyscript
57
58 This command runs a Python script file inside the `cmd2` application. See
59 [Python Scripts](./scripting.md#python-scripts) for more information.
60
61 ### run_script
62
63 This command runs commands in a script file that is encoded as either ASCII or UTF-8 text. See
64 [Command Scripts](./scripting.md#command-scripts) for more information.
65
66 ### \_relative_run_script
67
68 **This command is hidden from the help that's visible to end users.** It runs a script like
69 [run_script](#run_script) but does so using a path relative to the script that is currently
70 executing. This is useful when you have scripts that run other scripts. See
71 [Running Command Scripts](../features/scripting.md#running-command-scripts) for more information.
72
73 ### set
74
75 A list of all user-settable parameters, with brief comments, is viewable from within a running
76 application:
77
78 ```text
79 (Cmd) set
80 Name Value Description
81 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
82 allow_style Terminal Allow ANSI text style sequences in output (valid values: Always, Never, Terminal)
83 debug False Show full traceback on exception
84 echo False Echo command issued into output
85 editor vim Program used by 'edit'
86 max_column_completion_results 7 Maximum number of completion results to display in a single column
87 max_completion_table_items 50 Maximum number of completion results allowed for a completion table to appear
88 quiet False Don't print nonessential feedback
89 scripts_add_to_history True Scripts and pyscripts add commands to history
90 timing False Report execution times
91 traceback_show_locals False Display local variables in tracebacks
92 ```
93
94 Any of these user-settable parameters can be set while running your app with the `set` command like
95 so:
96
97 ```text
98 (Cmd) set allow_style Never
99 ```
100
101 See [Settings](./settings.md) for more information.
102
103 ### shell
104
105 Execute a command as if at the operating system shell prompt:
106
107 ```text
108 (Cmd) shell pwd -P
109 /usr/local/bin
110 ```
111
112 ### shortcuts
113
114 This command lists available shortcuts. See [Shortcuts](./shortcuts_aliases_macros.md#shortcuts) for
115 more information.
116
117 ## Remove Builtin Commands
118
119 Developers may not want to offer all the commands built into [cmd2.Cmd][] to users of their
120 application. To remove a command you must delete the method implementing that command from the
121 [cmd2.Cmd][] object at runtime. For example, if you wanted to remove the [shell](#shell) command
122 from your application:
123
124 ```py
125 class NoShellApp(cmd2.Cmd):
126 """A simple cmd2 application."""
127
128 delattr(cmd2.Cmd, 'do_shell')
129 ```