summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rwxr-xr-xcmd2.py41
-rw-r--r--tests/conftest.py3
-rw-r--r--tests/test_cmd2.py45
-rw-r--r--tests/test_transcript.py4
-rw-r--r--tests/transcripts/from_cmdloop.txt4
6 files changed, 55 insertions, 45 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 144954ac..c4e6136c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,10 +13,13 @@
* Alternatively, see the **argparse_example.py** and **arg_print.py** examples
* The **__relative_load** command is now hidden from the help menu by default
* This command is not intended to be called from the command line, only from within scripts
+ * The **set** command now has an additional **-a/--all** option to also display read-only settings
* Deprecations
* The old **options** decorator for optparse-based argument parsing is now *deprecated*
* The old decorator is still present for now, but will eventually be removed in a future release
* ``cmd2`` no longer includes **optparse.make_option** so if your app needs it you need to import it directly from optparse
+ * The **cmdenvironment** has been removed and its functionality incorporated into the **-a/--all** argument to **set**
+ * The **show** command has been removed. Its functionality has always existing within **set** and continues to do so
## 0.7.9 (January 4, 2018)
diff --git a/cmd2.py b/cmd2.py
index baf3d84b..a1f02756 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1199,22 +1199,6 @@ class Cmd(cmd.Cmd):
return stop
- def do_cmdenvironment(self, _):
- """Summary report of interactive parameters."""
- self.poutput("""
- Commands are case-sensitive: {}
- Commands may be terminated with: {}
- Arguments at invocation allowed: {}
- Output redirection and pipes allowed: {}
- Parsing of @options commands:
- Shell lexer mode for command argument splitting: {}
- Strip Quotes after splitting arguments: {}
- Argument type: {}
- \n""".format(not self.case_insensitive, str(self.terminators), self.allow_cli_args, self.allow_redirection,
- "POSIX" if POSIX_SHLEX else "non-POSIX",
- "True" if STRIP_QUOTES_FOR_NON_POSIX and not POSIX_SHLEX else "False",
- "List of argument strings" if USE_ARG_LIST else "string of space-separated arguments"))
-
@with_argument_list
def do_help(self, arglist):
"""List available commands with "help" or detailed help with "help cmd"."""
@@ -1316,6 +1300,26 @@ class Cmd(cmd.Cmd):
len(fulloptions)))
return result
+ def cmdenvironment(self):
+ """Get a summary report of read-only settings which the user cannot modify at runtime.
+
+ :return: str - summary report of read-only settings which the user cannot modify at runtime
+ """
+ read_only_settings = """
+ Commands are case-sensitive: {}
+ Commands may be terminated with: {}
+ Arguments at invocation allowed: {}
+ Output redirection and pipes allowed: {}
+ Parsing of @options commands:
+ Shell lexer mode for command argument splitting: {}
+ Strip Quotes after splitting arguments: {}
+ Argument type: {}
+ """.format(not self.case_insensitive, str(self.terminators), self.allow_cli_args, self.allow_redirection,
+ "POSIX" if POSIX_SHLEX else "non-POSIX",
+ "True" if STRIP_QUOTES_FOR_NON_POSIX and not POSIX_SHLEX else "False",
+ "List of argument strings" if USE_ARG_LIST else "string of space-separated arguments")
+ return read_only_settings
+
def show(self, args, parameter):
param = ''
if parameter:
@@ -1332,10 +1336,15 @@ class Cmd(cmd.Cmd):
self.poutput('{} # {}'.format(result[p].ljust(maxlen), self.settable[p]))
else:
self.poutput(result[p])
+
+ # If user has requested to see all settings, also show read-only settings
+ if args.all:
+ self.poutput('\nRead only settings:{}'.format(self.cmdenvironment()))
else:
raise LookupError("Parameter '%s' not supported (type 'show' for list of parameters)." % param)
set_parser = argparse.ArgumentParser(description='show or set value of a parameter')
+ set_parser.add_argument('-a', '--all', action='store_true', help='display read-only settings as well')
set_parser.add_argument('-l', '--long', action='store_true', help='describe function of parameter')
set_parser.add_argument('settable', nargs='*', help='[param_name] [value]')
diff --git a/tests/conftest.py b/tests/conftest.py
index c9a9ab0e..e20d2511 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -15,8 +15,7 @@ import cmd2
# Help text for base cmd2.Cmd application
BASE_HELP = """Documented commands (type help <topic>):
========================================
-cmdenvironment help load pyscript run set shortcuts
-edit history py quit save shell
+edit help history load py pyscript quit run save set shell shortcuts
"""
# Help text for the history command
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 3295bb60..556578d5 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -54,7 +54,7 @@ def test_base_invalid_option(base_app, capsys):
run_cmd(base_app, 'set -z')
out, err = capsys.readouterr()
run_cmd(base_app, 'help set')
- expected = ['usage: set [-h] [-l] [settable [settable ...]]', 'set: error: unrecognized arguments: -z']
+ expected = ['usage: set [-h] [-a] [-l] [settable [settable ...]]', 'set: error: unrecognized arguments: -z']
assert normalize(str(err)) == expected
def test_base_shortcuts(base_app):
@@ -79,6 +79,25 @@ def test_base_show_long(base_app):
assert out == expected
+def test_base_show_readonly(base_app):
+ out = run_cmd(base_app, 'set -a')
+ expected = normalize(SHOW_TXT + '\nRead only settings:' + """
+ Commands are case-sensitive: {}
+ Commands may be terminated with: {}
+ Arguments at invocation allowed: {}
+ Output redirection and pipes allowed: {}
+ Parsing of @options commands:
+ Shell lexer mode for command argument splitting: {}
+ Strip Quotes after splitting arguments: {}
+ Argument type: {}
+
+""".format(not base_app.case_insensitive, base_app.terminators, base_app.allow_cli_args, base_app.allow_redirection,
+ "POSIX" if cmd2.POSIX_SHLEX else "non-POSIX",
+ "True" if cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.POSIX_SHLEX else "False",
+ "List of argument strings" if cmd2.USE_ARG_LIST else "string of space-separated arguments"))
+ assert out == expected
+
+
def test_base_set(base_app):
out = run_cmd(base_app, 'set quiet True')
expected = normalize("""
@@ -296,26 +315,6 @@ def test_history_with_span_index_error(base_app):
""")
assert out == expected
-
-def test_base_cmdenvironment(base_app):
- out = run_cmd(base_app, 'cmdenvironment')
- expected = normalize("""
-
- Commands are case-sensitive: {}
- Commands may be terminated with: {}
- Arguments at invocation allowed: {}
- Output redirection and pipes allowed: {}
- Parsing of @options commands:
- Shell lexer mode for command argument splitting: {}
- Strip Quotes after splitting arguments: {}
- Argument type: {}
-
-""".format(not base_app.case_insensitive, base_app.terminators, base_app.allow_cli_args, base_app.allow_redirection,
- "POSIX" if cmd2.POSIX_SHLEX else "non-POSIX",
- "True" if cmd2.STRIP_QUOTES_FOR_NON_POSIX and not cmd2.POSIX_SHLEX else "False",
- "List of argument strings" if cmd2.USE_ARG_LIST else "string of space-separated arguments"))
- assert out == expected
-
def test_base_load(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
filename = os.path.join(test_dir, 'script.txt')
@@ -1097,8 +1096,8 @@ def test_custom_help_menu(help_app):
expected = normalize("""
Documented commands (type help <topic>):
========================================
-cmdenvironment help load pyscript run set shortcuts
-edit history py quit save shell squat
+edit history py quit save shell squat
+help load pyscript run set shortcuts
Undocumented commands:
======================
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index 08cde665..193e135f 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -130,8 +130,8 @@ def test_base_with_transcript(_cmdline_app):
Documented commands (type help <topic>):
========================================
-cmdenvironment help load orate pyscript run say shell speak
-edit history mumble py quit save set shortcuts
+edit history mumble py quit save set shortcuts
+help load orate pyscript run say shell speak
(Cmd) help say
Repeats what you tell me to.
diff --git a/tests/transcripts/from_cmdloop.txt b/tests/transcripts/from_cmdloop.txt
index 401860ad..3deed8cf 100644
--- a/tests/transcripts/from_cmdloop.txt
+++ b/tests/transcripts/from_cmdloop.txt
@@ -5,8 +5,8 @@
Documented commands (type help <topic>):
========================================
-cmdenvironment help load orate pyscript run say shell speak/ */
-edit history mumble py quit save set shortcuts/ */
+edit history mumble py quit save set shortcuts/ */
+help load orate pyscript run say shell speak/ */
(Cmd) help say
Repeats what you tell me to.