Cmd2
cmd2::Cmd Class Reference
Inheritance diagram for cmd2::Cmd:
example::CmdLineApp pirate6::Pirate pirate7::Pirate pirate8::Pirate

List of all members.

Public Member Functions

def poutput
def perror
def pfeedback
def colorize
def do_cmdenvironment
def do_help
def __init__
def do_shortcuts
def preparse
def postparse
def parsed
def postparsing_precmd
def postparsing_postcmd
def func_named
def onecmd_plus_hooks
def complete_statement
def redirect_output
def restore_output
def onecmd
def pseudo_raw_input
def do_EOF
def do_quit
def select
def do_show
def do_set
def do_pause
def do_shell
def do_py
def do_history
def last_matching
def do_list
def do_ed
def do_save
def read_file_or_url
def do__relative_load
def do_load
def do_run
def fileimport
def runTranscriptTests
def run_commands_at_invocation
def cmdloop

Public Attributes

 stdout
 initial_stdout
 history
 pystate
 shortcuts
 keywords
 multilineCommand
 blankLineTerminationParser
 blankLineTerminator
 multilineParser
 singleLineParser
 parser
 inputParser
 kept_sys
 redirect
 lastcmd
 old_completer
 intro
 stdin
 use_rawinput
 prompt
 continuation_prompt

Static Public Attributes

 echo = False
 case_insensitive = True
string continuation_prompt = '> '
 timing = False
string legalChars = u'!#$%.:?@_'
dictionary shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
string excludeFromHistory = '''run r list l history hi ed edit li eof'''
 default_to_shell = False
string noSpecialParse = 'set ed edit exit'
string defaultExtension = 'txt'
string default_file_name = 'command.txt'
 abbrev = True
 current_script_dir = None
list reserved_words = []
 feedback_to_output = False
 quiet = False
 debug = False
 locals_in_py = True
 kept_state = None
string redirector = '>'
tuple settable
tuple editor = os.environ.get('EDITOR')
string editor = 'notepad'
dictionary colorcodes
tuple colors = (platform.system() != 'Windows')
tuple prefixParser = pyparsing.Empty()
tuple commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
tuple commentInProgress = pyparsing.Literal('/*')
list terminators = [';']
 blankLinesAllowed = False
list multilineCommands = []
 do_eof = do_EOF
 do_exit = do_quit
 do_q = do_quit
string help = "describe function of parameter"
 do_hi = do_history
 do_l = do_list
 do_li = do_list
 do_edit = do_ed
tuple saveparser
tuple urlre = re.compile('(https?://[-\\w\\./]+)')
 do__load = do_load
 do_r = do_run

Detailed Description

Definition at line 361 of file cmd2.py.


Constructor & Destructor Documentation

def cmd2::Cmd::__init__ (   self,
  args,
  kwargs 
)

Definition at line 469 of file cmd2.py.


Member Function Documentation

def cmd2::Cmd::cmdloop (   self)

Definition at line 1283 of file cmd2.py.

def cmd2::Cmd::colorize (   self,
  val,
  color 
)
Given a string (``val``), returns that string wrapped in UNIX-style 
   special characters that turn on (and then off) text color and style.
   If the ``colors`` environment paramter is ``False``, or the application
   is running on Windows, will return ``val`` unchanged.
   ``color`` should be one of the supported strings (or styles):
   red/blue/green/cyan/magenta, bold, underline

Definition at line 435 of file cmd2.py.

def cmd2::Cmd::complete_statement (   self,
  line 
)
Keep accepting lines of input until the command is complete.

Definition at line 794 of file cmd2.py.

def cmd2::Cmd::do__relative_load (   self,
  arg = None 
)
Runs commands in script at file or URL; if this is called from within an
already-running script, the filename will be interpreted relative to the 
already-running script's directory.

Definition at line 1206 of file cmd2.py.

def cmd2::Cmd::do_cmdenvironment (   self,
  args 
)
Summary report of interactive parameters.

Definition at line 446 of file cmd2.py.

def cmd2::Cmd::do_ed (   self,
  arg 
)
ed: edit most recent command in text editor
ed [N]: edit numbered command from history
ed [filename]: edit specified file name

commands are run after editor is closed.
"set edit (program-name)" or set  EDITOR environment variable
to control which editing program is used.

Definition at line 1128 of file cmd2.py.

def cmd2::Cmd::do_EOF (   self,
  arg 
)

Definition at line 937 of file cmd2.py.

def cmd2::Cmd::do_help (   self,
  arg 
)

Definition at line 457 of file cmd2.py.

def cmd2::Cmd::do_history (   self,
  arg,
  opts 
)
history [arg]: lists past commands issued

| no arg:         list all
| arg is integer: list one history item, by index
| arg is string:  string search
| arg is /enclosed in forward-slashes/: regular expression search

Definition at line 1083 of file cmd2.py.

def cmd2::Cmd::do_list (   self,
  arg 
)
list [arg]: lists last command issued

no arg -> list most recent command
arg is integer -> list one history item, by index
a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end)
arg is string -> list all commands matching string search
arg is /enclosed in forward-slashes/ -> regular expression search

Definition at line 1108 of file cmd2.py.

def cmd2::Cmd::do_load (   self,
  arg = None 
)
Runs script of command(s) from a file or URL.

Definition at line 1218 of file cmd2.py.

def cmd2::Cmd::do_pause (   self,
  arg 
)

Definition at line 1031 of file cmd2.py.

def cmd2::Cmd::do_py (   self,
  arg 
)
py <command>: Executes a Python command.
py: Enters interactive Python mode.
End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
Non-python commands can be issued with ``cmd("your command")``.
Run python code from external files with ``run("filename.py")``

Definition at line 1039 of file cmd2.py.

def cmd2::Cmd::do_quit (   self,
  arg 
)

Reimplemented in pirate6::Pirate, pirate7::Pirate, and pirate8::Pirate.

Definition at line 941 of file cmd2.py.

def cmd2::Cmd::do_run (   self,
  arg 
)
run [arg]: re-runs an earlier command

no arg -> run most recent command
arg is integer -> run one history item, by index
arg is string -> run most recent command by string search
arg is /enclosed in forward-slashes/ -> run most recent by regex

Definition at line 1243 of file cmd2.py.

def cmd2::Cmd::do_save (   self,
  arg 
)
`save [N] [filename.ext]`

Saves command from history to file.

| N => Number of command (from history), or `*`; 
|      most recent command if omitted

Definition at line 1160 of file cmd2.py.

def cmd2::Cmd::do_set (   self,
  arg 
)
Sets a cmd2 parameter.  Accepts abbreviated parameter names so long
as there is no ambiguity.  Call without arguments for a list of 
settable parameters with their values.

Definition at line 1000 of file cmd2.py.

def cmd2::Cmd::do_shell (   self,
  arg 
)

Definition at line 1035 of file cmd2.py.

def cmd2::Cmd::do_shortcuts (   self,
  args 
)
Lists single-key shortcuts available.

Definition at line 479 of file cmd2.py.

def cmd2::Cmd::do_show (   self,
  arg,
  opts 
)
Shows value of a parameter.

Definition at line 982 of file cmd2.py.

def cmd2::Cmd::fileimport (   self,
  statement,
  source 
)

Definition at line 1258 of file cmd2.py.

def cmd2::Cmd::func_named (   self,
  arg 
)

Definition at line 755 of file cmd2.py.

def cmd2::Cmd::last_matching (   self,
  arg 
)

Definition at line 1100 of file cmd2.py.

def cmd2::Cmd::onecmd (   self,
  line 
)
Interpret the argument as though it had been typed in response
to the prompt.

This may be overridden, but should not normally need to be;
see the precmd() and postcmd() methods for useful execution hooks.
The return value is a flag indicating whether interpretation of
commands by the interpreter should stop.

This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`.

Definition at line 844 of file cmd2.py.

def cmd2::Cmd::onecmd_plus_hooks (   self,
  line 
)

Definition at line 766 of file cmd2.py.

def cmd2::Cmd::parsed (   self,
  raw,
  kwargs 
)

Definition at line 726 of file cmd2.py.

def cmd2::Cmd::perror (   self,
  errmsg,
  statement = None 
)

Definition at line 404 of file cmd2.py.

def cmd2::Cmd::pfeedback (   self,
  msg 
)
For printing nonessential feedback.  Can be silenced with `quiet`.
   Inclusion in redirected output is controlled by `feedback_to_output`.

Definition at line 408 of file cmd2.py.

def cmd2::Cmd::postparse (   self,
  parseResult 
)

Definition at line 723 of file cmd2.py.

def cmd2::Cmd::postparsing_postcmd (   self,
  stop 
)

Definition at line 752 of file cmd2.py.

def cmd2::Cmd::postparsing_precmd (   self,
  statement 
)

Definition at line 749 of file cmd2.py.

def cmd2::Cmd::poutput (   self,
  msg 
)
Convenient shortcut for self.stdout.write(); adds newline if necessary.

Definition at line 398 of file cmd2.py.

def cmd2::Cmd::preparse (   self,
  raw,
  kwargs 
)

Definition at line 721 of file cmd2.py.

def cmd2::Cmd::pseudo_raw_input (   self,
  prompt 
)
copied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdout

Definition at line 876 of file cmd2.py.

def cmd2::Cmd::read_file_or_url (   self,
  fname 
)

Definition at line 1189 of file cmd2.py.

def cmd2::Cmd::redirect_output (   self,
  statement 
)

Definition at line 809 of file cmd2.py.

def cmd2::Cmd::restore_output (   self,
  statement 
)

Definition at line 830 of file cmd2.py.

def cmd2::Cmd::run_commands_at_invocation (   self,
  callargs 
)

Definition at line 1278 of file cmd2.py.

def cmd2::Cmd::runTranscriptTests (   self,
  callargs 
)

Definition at line 1268 of file cmd2.py.

def cmd2::Cmd::select (   self,
  options,
  prompt = 'Your choice? ' 
)
Presents a numbered menu to the user.  Modelled after
   the bash shell's SELECT.  Returns the item chosen.
   
   Argument ``options`` can be:

     | a single string -> will be split into one-word options
     | a list of strings -> will be offered as options
     | a list of tuples -> interpreted as (value, text), so 
                   that the return value can differ from
                   the text advertised to the user 

Definition at line 946 of file cmd2.py.


Member Data Documentation

cmd2::Cmd::abbrev = True [static]

Definition at line 374 of file cmd2.py.

cmd2::Cmd::blankLinesAllowed = False [static]

Definition at line 490 of file cmd2.py.

Definition at line 667 of file cmd2.py.

Definition at line 667 of file cmd2.py.

cmd2::Cmd::case_insensitive = True [static]

Definition at line 363 of file cmd2.py.

dictionary cmd2::Cmd::colorcodes [static]
Initial value:
{'bold':{True:'\x1b[1m',False:'\x1b[22m'},
                  'cyan':{True:'\x1b[36m',False:'\x1b[39m'},
                  'blue':{True:'\x1b[34m',False:'\x1b[39m'},
                  'red':{True:'\x1b[31m',False:'\x1b[39m'},
                  'magenta':{True:'\x1b[35m',False:'\x1b[39m'},
                  'green':{True:'\x1b[32m',False:'\x1b[39m'},
                  'underline':{True:'\x1b[4m',False:'\x1b[24m'}}

Definition at line 427 of file cmd2.py.

tuple cmd2::Cmd::colors = (platform.system() != 'Windows') [static]

Definition at line 434 of file cmd2.py.

tuple cmd2::Cmd::commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment]) [static]

Definition at line 485 of file cmd2.py.

tuple cmd2::Cmd::commentInProgress = pyparsing.Literal('/*') [static]

Definition at line 487 of file cmd2.py.

string cmd2::Cmd::continuation_prompt = '> ' [static]

Definition at line 364 of file cmd2.py.

Definition at line 1218 of file cmd2.py.

Definition at line 375 of file cmd2.py.

cmd2::Cmd::debug = False [static]

Definition at line 379 of file cmd2.py.

string cmd2::Cmd::default_file_name = 'command.txt' [static]

Definition at line 373 of file cmd2.py.

cmd2::Cmd::default_to_shell = False [static]

Reimplemented in pirate7::Pirate, and pirate8::Pirate.

Definition at line 370 of file cmd2.py.

string cmd2::Cmd::defaultExtension = 'txt' [static]

Definition at line 372 of file cmd2.py.

cmd2::Cmd::do__load = do_load [static]

Definition at line 1241 of file cmd2.py.

cmd2::Cmd::do_edit = do_ed [static]

Definition at line 1155 of file cmd2.py.

cmd2::Cmd::do_eof = do_EOF [static]

Definition at line 939 of file cmd2.py.

cmd2::Cmd::do_exit = do_quit [static]

Definition at line 943 of file cmd2.py.

cmd2::Cmd::do_hi = do_history [static]

Definition at line 1124 of file cmd2.py.

cmd2::Cmd::do_l = do_list [static]

Definition at line 1125 of file cmd2.py.

cmd2::Cmd::do_li = do_list [static]

Definition at line 1126 of file cmd2.py.

cmd2::Cmd::do_q = do_quit [static]

Definition at line 944 of file cmd2.py.

cmd2::Cmd::do_r = do_run [static]

Definition at line 1256 of file cmd2.py.

cmd2::Cmd::echo = False [static]

Definition at line 362 of file cmd2.py.

tuple cmd2::Cmd::editor = os.environ.get('EDITOR') [static]

Definition at line 418 of file cmd2.py.

string cmd2::Cmd::editor = 'notepad' [static]

Definition at line 421 of file cmd2.py.

string cmd2::Cmd::excludeFromHistory = '''run r list l history hi ed edit li eof''' [static]

Definition at line 369 of file cmd2.py.

Definition at line 377 of file cmd2.py.

string cmd2::Cmd::help = "describe function of parameter" [static]

Reimplemented in pirate8::Pirate.

Definition at line 981 of file cmd2.py.

Definition at line 469 of file cmd2.py.

Definition at line 469 of file cmd2.py.

Definition at line 667 of file cmd2.py.

Definition at line 898 of file cmd2.py.

cmd2::Cmd::kept_state = None [static]

Definition at line 381 of file cmd2.py.

Definition at line 809 of file cmd2.py.

Definition at line 469 of file cmd2.py.

Definition at line 854 of file cmd2.py.

string cmd2::Cmd::legalChars = u'!#$%.:?@_' [static]

Definition at line 367 of file cmd2.py.

cmd2::Cmd::locals_in_py = True [static]

Definition at line 380 of file cmd2.py.

Definition at line 667 of file cmd2.py.

list cmd2::Cmd::multilineCommands = [] [static]

Reimplemented in pirate7::Pirate, pirate8::Pirate, and example::CmdLineApp.

Definition at line 491 of file cmd2.py.

Definition at line 667 of file cmd2.py.

string cmd2::Cmd::noSpecialParse = 'set ed edit exit' [static]

Definition at line 371 of file cmd2.py.

Definition at line 898 of file cmd2.py.

Definition at line 667 of file cmd2.py.

tuple cmd2::Cmd::prefixParser = pyparsing.Empty() [static]

Definition at line 484 of file cmd2.py.

Reimplemented in pirate6::Pirate, pirate7::Pirate, and pirate8::Pirate.

Definition at line 1218 of file cmd2.py.

Definition at line 469 of file cmd2.py.

cmd2::Cmd::quiet = False [static]

Definition at line 378 of file cmd2.py.

Definition at line 809 of file cmd2.py.

string cmd2::Cmd::redirector = '>' [static]

Reimplemented in example::CmdLineApp.

Definition at line 382 of file cmd2.py.

list cmd2::Cmd::reserved_words = [] [static]

Definition at line 376 of file cmd2.py.

tuple cmd2::Cmd::saveparser [static]
Initial value:
(pyparsing.Optional(pyparsing.Word(pyparsing.nums)^'*')("idx") + 
                  pyparsing.Optional(pyparsing.Word(legalChars + '/\\'))("fname") +
                  pyparsing.stringEnd)

Definition at line 1157 of file cmd2.py.

tuple cmd2::Cmd::settable [static]
Initial value:
stubbornDict('''
    prompt
    colors                Colorized output (*nix only)
    continuation_prompt   On 2nd+ line of input
    debug                 Show full error stack on error
    default_file_name     for ``save``, ``load``, etc.
    editor                Program used by ``edit``      
    case_insensitive      upper- and lower-case both OK
    feedback_to_output    include nonessentials in `|`, `>` results 
    quiet                 Don't print nonessential feedback
    echo                  Echo command issued into output
    timing                Report execution times
    abbrev                Accept abbreviated commands
    ''')

Reimplemented in pirate7::Pirate, and pirate8::Pirate.

Definition at line 383 of file cmd2.py.

dictionary cmd2::Cmd::shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'} [static]

Definition at line 368 of file cmd2.py.

Definition at line 469 of file cmd2.py.

Definition at line 667 of file cmd2.py.

Definition at line 1218 of file cmd2.py.

Definition at line 440 of file cmd2.py.

list cmd2::Cmd::terminators = [';'] [static]

Reimplemented in pirate7::Pirate, and pirate8::Pirate.

Definition at line 489 of file cmd2.py.

cmd2::Cmd::timing = False [static]

Definition at line 365 of file cmd2.py.

tuple cmd2::Cmd::urlre = re.compile('(https?://[-\\w\\./]+)') [static]

Definition at line 1217 of file cmd2.py.

Definition at line 1218 of file cmd2.py.


The documentation for this class was generated from the following file: