File: multiline_commands.md

package info (click to toggle)
cmd2 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,664 kB
  • sloc: python: 17,488; makefile: 114; sh: 39; javascript: 7
file content (29 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Multiline Commands

Command input may span multiple lines for the commands whose names are listed in the
`multiline_commands` argument to [cmd2.Cmd.\_\_init\_\_][cmd2.Cmd.__init__]. These commands will be
executed only after the user has entered a _terminator_. By default, the command terminator is `;`.
Specifying the `terminators` optional argument to `cmd2.Cmd.__init__()` allows different
terminators. A blank line is _always_ considered a command terminator (cannot be overridden).

In multiline commands, output redirection characters like `>` and `|` are part of the command
arguments unless they appear after the terminator.

## Continuation prompt

When a user types a **Multiline Command** it may span more than one line of input. The prompt for
the first line of input is specified by the [cmd2.Cmd.prompt][] instance attribute - see
[Customizing the Prompt](./prompt.md#customizing-the-prompt). The prompt for subsequent lines of
input is defined by the [cmd2.Cmd.continuation_prompt][] attribute.

## Use cases

Multiline commands should probably be used sparingly in order to preserve a good user experience for
your `cmd2`-based line-oriented command interpreter application.

However, some use cases benefit significantly from the ability to have commands that span more than
one line. For example, you might want the ability for your user to type in a SQL command, which can
often span lines and which are terminated with a semicolon.

We estimate that less than 5 percent of `cmd2` applications use this feature. But it is here for
those use cases where it provides value.