Skip to content

Commit 3126eb7

Browse files
committed
No longer using -1 as an exit code
1 parent 3a4893e commit 3126eb7

File tree

6 files changed

+7
-6
lines changed

6 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Settables now have new initialization parameters. It is now a required parameter to supply the reference to the
2222
object that holds the settable attribute. `cmd2.Cmd.settables` is no longer a public dict attribute - it is now a
2323
property that aggregates all Settables across all registered CommandSets.
24+
* Failed transcript testing now sets self.exit_code to 1 instead of -1.
2425
* Enhancements
2526
* Added support for custom tab completion and up-arrow input history to `cmd2.Cmd2.read_input`.
2627
See [read_input.py](https://github.com/python-cmd2/cmd2/blob/master/examples/read_input.py)

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4750,7 +4750,7 @@ class TestMyAppCase(Cmd2TestCase):
47504750
transcripts_expanded = utils.files_from_glob_patterns(transcript_paths, access=os.R_OK)
47514751
if not transcripts_expanded:
47524752
self.perror('No test files found - nothing to test')
4753-
self.exit_code = -1
4753+
self.exit_code = 1
47544754
return
47554755

47564756
verinfo = ".".join(map(str, sys.version_info[:3]))
@@ -4787,7 +4787,7 @@ class TestMyAppCase(Cmd2TestCase):
47874787
self.perror(error_str[start:])
47884788

47894789
# Return a failure error code to support automated transcript-based testing
4790-
self.exit_code = -1
4790+
self.exit_code = 1
47914791

47924792
def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None: # pragma: no cover
47934793
"""

docs/features/commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ The ``cmd2.Cmd`` object sets an ``exit_code`` attribute to zero when it is
142142
instantiated. The value of this attribute is returned from the ``cmdloop()``
143143
call. Therefore, if you don't do anything with this attribute in your code,
144144
``cmdloop()`` will (almost) always return zero. There are a few built-in
145-
``cmd2`` commands which set ``exit_code`` to ``-1`` if an error occurs.
145+
``cmd2`` commands which set ``exit_code`` to ``1`` if an error occurs.
146146

147147
You can use this capability to easily return your own values to the operating
148148
system shell::

examples/exit_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def do_exit(self, arg_list: List[str]) -> bool:
2828
self.exit_code = int(arg_list[0])
2929
except ValueError:
3030
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
31-
self.exit_code = -1
31+
self.exit_code = 1
3232

3333
return True
3434

examples/pirate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def postcmd(self, stop, line):
4646
self.poutput('Now we gots {0} doubloons'.format(self.gold))
4747
if self.gold < 0:
4848
self.poutput("Off to debtorrr's prison.")
49-
self.exit_code = -1
49+
self.exit_code = 1
5050
stop = True
5151
return stop
5252

tests/test_cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ def do_exit(self, arg_list) -> bool:
23262326
self.exit_code = int(arg_list[0])
23272327
except ValueError:
23282328
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
2329-
self.exit_code = -1
2329+
self.exit_code = 1
23302330

23312331
# Return True to stop the command loop
23322332
return True

0 commit comments

Comments
 (0)