summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-23 11:51:24 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-23 11:51:24 -0400
commit3126eb792816e09ce56f24262447077df1bdc0c3 (patch)
tree3a80de210c8fc8fe49a0597e7b45bd638699a231
parent3a4893ec32c6d38cad344667fead93e2eed8dc88 (diff)
downloadcmd2-git-exit_code.tar.gz
No longer using -1 as an exit codeexit_code
-rw-r--r--CHANGELOG.md1
-rw-r--r--cmd2/cmd2.py4
-rw-r--r--docs/features/commands.rst2
-rwxr-xr-xexamples/exit_code.py2
-rwxr-xr-xexamples/pirate.py2
-rwxr-xr-xtests/test_cmd2.py2
6 files changed, 7 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 31a70aff..4f3b9472 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
* Settables now have new initialization parameters. It is now a required parameter to supply the reference to the
object that holds the settable attribute. `cmd2.Cmd.settables` is no longer a public dict attribute - it is now a
property that aggregates all Settables across all registered CommandSets.
+ * Failed transcript testing now sets self.exit_code to 1 instead of -1.
* Enhancements
* Added support for custom tab completion and up-arrow input history to `cmd2.Cmd2.read_input`.
See [read_input.py](https://github.com/python-cmd2/cmd2/blob/master/examples/read_input.py)
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 3430ad44..68ad8201 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -4750,7 +4750,7 @@ class Cmd(cmd.Cmd):
transcripts_expanded = utils.files_from_glob_patterns(transcript_paths, access=os.R_OK)
if not transcripts_expanded:
self.perror('No test files found - nothing to test')
- self.exit_code = -1
+ self.exit_code = 1
return
verinfo = ".".join(map(str, sys.version_info[:3]))
@@ -4787,7 +4787,7 @@ class Cmd(cmd.Cmd):
self.perror(error_str[start:])
# Return a failure error code to support automated transcript-based testing
- self.exit_code = -1
+ self.exit_code = 1
def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None: # pragma: no cover
"""
diff --git a/docs/features/commands.rst b/docs/features/commands.rst
index 3b35a19b..66745469 100644
--- a/docs/features/commands.rst
+++ b/docs/features/commands.rst
@@ -142,7 +142,7 @@ The ``cmd2.Cmd`` object sets an ``exit_code`` attribute to zero when it is
instantiated. The value of this attribute is returned from the ``cmdloop()``
call. Therefore, if you don't do anything with this attribute in your code,
``cmdloop()`` will (almost) always return zero. There are a few built-in
-``cmd2`` commands which set ``exit_code`` to ``-1`` if an error occurs.
+``cmd2`` commands which set ``exit_code`` to ``1`` if an error occurs.
You can use this capability to easily return your own values to the operating
system shell::
diff --git a/examples/exit_code.py b/examples/exit_code.py
index 80cef62f..440fc595 100755
--- a/examples/exit_code.py
+++ b/examples/exit_code.py
@@ -28,7 +28,7 @@ class ReplWithExitCode(cmd2.Cmd):
self.exit_code = int(arg_list[0])
except ValueError:
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
- self.exit_code = -1
+ self.exit_code = 1
return True
diff --git a/examples/pirate.py b/examples/pirate.py
index f91b99d7..3a9b7b36 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -46,7 +46,7 @@ class Pirate(cmd2.Cmd):
self.poutput('Now we gots {0} doubloons'.format(self.gold))
if self.gold < 0:
self.poutput("Off to debtorrr's prison.")
- self.exit_code = -1
+ self.exit_code = 1
stop = True
return stop
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index e369a9cf..44d2b304 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -2326,7 +2326,7 @@ class ReplWithExitCode(cmd2.Cmd):
self.exit_code = int(arg_list[0])
except ValueError:
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
- self.exit_code = -1
+ self.exit_code = 1
# Return True to stop the command loop
return True