summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-07-05 11:28:40 -0600
committerkotfu <kotfu@kotfu.net>2018-07-05 11:28:40 -0600
commit9a6a2b2c25c19e82c661c7ca602f528312e89a62 (patch)
treee0e330ccfd1e263c69406c6747da1e3bd1568258 /cmd2
parent985e790c594a2c48804ffa201f9253eb32a59c8b (diff)
parentd80d672f47c3141bf4dfd7fc31818aa36d65a832 (diff)
downloadcmd2-git-9a6a2b2c25c19e82c661c7ca602f528312e89a62.tar.gz
Merge branch 'master' into plugin_functions
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/__init__.py3
-rwxr-xr-xcmd2/argparse_completer.py33
-rw-r--r--cmd2/cmd2.py7
-rw-r--r--cmd2/pyscript_bridge.py2
4 files changed, 36 insertions, 9 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py
index e9a82acb..f61b7165 100644
--- a/cmd2/__init__.py
+++ b/cmd2/__init__.py
@@ -1,5 +1,6 @@
#
# -*- coding: utf-8 -*-
"""This simply imports certain things for backwards compatibility."""
-from .cmd2 import __version__, Cmd, CmdResult, Statement, EmptyStatement, categorize
+from .cmd2 import __version__, Cmd, Statement, EmptyStatement, categorize
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
+from .pyscript_bridge import CommandResult \ No newline at end of file
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 995aeb48..60af25de 100755
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -81,6 +81,33 @@ ACTION_DESCRIPTIVE_COMPLETION_HEADER = 'desc_header'
class CompletionItem(str):
+ """
+ Completion item with descriptive text attached
+
+ Returning this instead of a regular string for completion results will signal the
+ autocompleter to output the completions results in a table of completion tokens
+ with descriptions instead of just a table of tokens.
+
+ For example, you'd see this:
+ TOKEN Description
+ MY_TOKEN Info about my token
+ SOME_TOKEN Info about some token
+ YET_ANOTHER Yet more info
+
+ Instead of this:
+ TOKEN_ID SOME_TOKEN YET_ANOTHER
+
+ This is especially useful if you want to complete ID numbers in a more
+ user-friendly manner. For example, you can provide this:
+
+ ITEM_ID Item Name
+ 1 My item
+ 2 Another item
+ 3 Yet another item
+
+ Instead of this:
+ 1 2 3
+ """
def __new__(cls, o, desc='', *args, **kwargs) -> str:
return str.__new__(cls, o, *args, **kwargs)
@@ -1196,9 +1223,9 @@ class ACArgumentParser(argparse.ArgumentParser):
# twice (which may fail) if the argument was given, but
# only if it was defined already in the namespace
if (action.default is not None and
- isinstance(action.default, str) and
- hasattr(namespace, action.dest) and
- action.default is getattr(namespace, action.dest)):
+ isinstance(action.default, str) and
+ hasattr(namespace, action.dest) and
+ action.default is getattr(namespace, action.dest)):
setattr(namespace, action.dest,
self._get_value(action, action.default))
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 140d7034..8db7cef3 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -116,7 +116,7 @@ try:
except ImportError: # pragma: no cover
ipython_available = False
-__version__ = '0.9.2a'
+__version__ = '0.9.3'
# optional attribute, when tagged on a function, allows cmd2 to categorize commands
@@ -306,7 +306,6 @@ class Cmd(cmd.Cmd):
Line-oriented command interpreters are often useful for test harnesses, internal tools, and rapid prototypes.
"""
# Attributes used to configure the StatementParser, best not to change these at runtime
- blankLinesAllowed = False
multiline_commands = []
shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
aliases = dict()
@@ -459,7 +458,7 @@ class Cmd(cmd.Cmd):
if startup_script is not None:
startup_script = os.path.expanduser(startup_script)
if os.path.exists(startup_script) and os.path.getsize(startup_script) > 0:
- self.cmdqueue.append('load {}'.format(startup_script))
+ self.cmdqueue.append("load '{}'".format(startup_script))
############################################################################################################
# The following variables are used by tab-completion functions. They are reset each time complete() is run
@@ -3408,7 +3407,7 @@ class Statekeeper(object):
class CmdResult(utils.namedtuple_with_two_defaults('CmdResult', ['out', 'err', 'war'])):
- """Derive a class to store results from a named tuple so we can tweak dunder methods for convenience.
+ """DEPRECATED: Derive a class to store results from a named tuple so we can tweak dunder methods for convenience.
This is provided as a convenience and an example for one possible way for end users to store results in
the self._last_result attribute of cmd2.Cmd class instances. See the "python_scripting.py" example for how it can
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index 9353e611..3f58ab84 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -22,7 +22,7 @@ from .argparse_completer import _RangeAction
from .utils import namedtuple_with_defaults
-class CommandResult(namedtuple_with_defaults('CmdResult', ['stdout', 'stderr', 'data'])):
+class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr', 'data'])):
"""Encapsulates the results from a command.
Named tuple attributes