summaryrefslogtreecommitdiff
path: root/docs/features/commands.rst
blob: 6a8fedeee011aab16531e1eef9cd2ca370a6ce4d (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Commands
========

.. _cmd: https://docs.python.org/3/library/cmd.html

How to create a command with a ``do_command`` method,

Parsed statements
-----------------

``cmd2`` passes ``arg`` to a ``do_`` method (or ``default``) as a Statement, a
subclass of string that includes many attributes of the parsed input:

command
    Name of the command called

args
    The arguments to the command with output redirection
    or piping to shell commands removed

command_and_args
    A string of just the command and the arguments, with
    output redirection or piping to shell commands removed

argv
    A list of arguments a-la ``sys.argv``, including
    the command as ``argv[0]`` and the subsequent
    arguments as additional items in the list.
    Quotes around arguments will be stripped as will
    any output redirection or piping portions of the command

raw
    Full input exactly as typed.

terminator
    Character used to end a multiline command



If ``Statement`` does not contain an attribute, querying for it will return
``None``.

(Getting ``arg`` as a ``Statement`` is technically "free", in that it requires
no application changes from the cmd_ standard, but there will be no result
unless you change your application to *use* any of the additional attributes.)