cmd_extensions module¶
Extensions to cmd.Cmd used by several programs.
Module author: Michael S. Chapman <chapmami@ohsu.edu>
Authors: | Michael S. Chapman <chapmami@ohsu.edu>, Oregon Health & Science University |
---|---|
Version: | 0.5, March 23, 2016 |
Changed in version 8/13/10.
-
class
cmd_extensions.
Extensions
¶ Bases:
object
-
do_cmd_file
(rest)¶ Read commands from a file.
-
do_echo
(rest)¶
-
do_help_all
(rest)¶ Lists all commands.
-
do_null
(rest)¶
-
do_parrot
(rest)¶ Echo user commands (for documentation of log files).
-
do_test
(rest)¶ Run a program developer’s test.
-
do_value
(rest)¶ Echo the value of a program option.
-
emptyline
()¶
-
help_cmd_file
()¶
-
help_echo
()¶
-
help_help_all
()¶
-
help_parrot
()¶
-
help_test
()¶
-
help_value
()¶
-
static
parseargs
(text, names, types, separator=', ')¶ Parse a (comma-separated) list (of positional arguments).
Parameters: - text (string) – to be parsed
- names (sequence of strings, e.g. (‘arg1’, ‘arg2’)) – (in order)
- types (sequence) – data types, e.g. (float, int)
- separator (string) – between arguments
Returns: dictionary of arguments {name: value}, rest of text
Return type: dict, string or NoneType
-
static
parseopt
(text, name, separator='--')¶ Simple parser for boolean command option.
Parameters: - text (string) – to be parsed
- name (string) – option
- separator (string) – between arguments, eg. ‘–’ or ‘-‘
Returns: whether option set, text with option stripped
Return type: bool, text
-
static
parseopts
(text, names, types, separator=', ', globals=None, locals=None)¶ Parse a (comma-separated) list of named arguments.
Like function-call parser, except just naming the argument is equivalent to argument = True.
Parameters: - text (string) – to be parsed, e.g. (‘arg1’, ‘arg2 = val2’)
- names (sequence of strings,) – check all arguments in this list (if present)
- types (sequence) – check data types, e.g. (float, int) if present, requires names
- separator (string) – between arguments
Returns: dictionary of arguments {name: value}
Return type: dict
-
precmd
(s)¶
-
preloop
()¶
-
static
protectedSplit
(text, separator=None)¶ Divide into words w/ separator not protected by quotes, brackets.
Parameters: - text (string) – to be parsed
- separator (string) – token separator, if None - any whitespace.
-
static
quoted
(text)¶
-
static
token
(text, separator=None)¶ 1st token before a separator not protected by quotes, brackets.
Parameters: - text (string) – to be parsed
- separator (string) – token separator, if None - any whitespace.
-