lib-cli-exit-tools 1.2.0__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/CHANGELOG.md +4 -0
  2. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/PKG-INFO +1 -1
  3. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/docs/system-design/reference.md +2 -2
  4. lib_cli_exit_tools-1.3.0/notebooks/Quickstart.ipynb +209 -0
  5. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/packaging/brew/Formula/lib-cli-exit-tools.rb +2 -2
  6. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/packaging/conda/recipe/meta.yaml +1 -1
  7. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/packaging/nix/flake.nix +1 -1
  8. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/pyproject.toml +1 -1
  9. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/lib_cli_exit_tools.py +58 -16
  10. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/tests/test_lib_extra.py +1 -1
  11. lib_cli_exit_tools-1.2.0/notebooks/Quickstart.ipynb +0 -121
  12. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/.env.example +0 -0
  13. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/.github/workflows/ci.yml +0 -0
  14. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/.github/workflows/codeql.yml +0 -0
  15. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/.github/workflows/release.yml +0 -0
  16. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/.gitignore +0 -0
  17. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/AGENTS.md +0 -0
  18. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/CONTRIBUTING.md +0 -0
  19. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/DEVELOPMENT.md +0 -0
  20. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/LICENSE +0 -0
  21. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/Makefile +0 -0
  22. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/README.md +0 -0
  23. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/codecov.yml +0 -0
  24. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/packaging/README.md +0 -0
  25. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/qlty.toml +0 -0
  26. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/__init__.py +0 -0
  27. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/_utils.py +0 -0
  28. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/build.py +0 -0
  29. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/bump.py +0 -0
  30. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/bump_major.py +0 -0
  31. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/bump_minor.py +0 -0
  32. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/bump_patch.py +0 -0
  33. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/bump_version.py +0 -0
  34. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/clean.py +0 -0
  35. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/dev.py +0 -0
  36. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/generate_nix_flake.py +0 -0
  37. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/install.py +0 -0
  38. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/menu.py +0 -0
  39. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/push.py +0 -0
  40. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/release.py +0 -0
  41. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/run_cli.py +0 -0
  42. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/test.py +0 -0
  43. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/scripts/version_current.py +0 -0
  44. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/__init__.py +0 -0
  45. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/__init__conf__.py +0 -0
  46. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/__main__.py +0 -0
  47. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/cli.py +0 -0
  48. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/src/lib_cli_exit_tools/py.typed +0 -0
  49. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/tests/test_cli.py +0 -0
  50. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/tests/test_cli_extra.py +0 -0
  51. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/tests/test_exit_tools.py +0 -0
  52. {lib_cli_exit_tools-1.2.0 → lib_cli_exit_tools-1.3.0}/tests/test_extend_cli.py +0 -0
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.0] - 2025-09-25
4
+
5
+ - colored traceback
6
+
3
7
  ## [1.2.0] - 2025-09-25
4
8
 
5
9
  - use rich-click instead of click, minor fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lib_cli_exit_tools
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: CLI exit handling helpers: clean signals, exit codes, and error printing
5
5
  Project-URL: Homepage, https://github.com/bitranox/lib_cli_exit_tools
6
6
  Project-URL: Repository, https://github.com/bitranox/lib_cli_exit_tools.git
@@ -138,9 +138,9 @@ The package is the core runtime library for handling CLI exits within the broade
138
138
  **Location:** `lib_cli_exit_tools/lib_cli_exit_tools.py`
139
139
 
140
140
  #### Function: print_exception_message
141
- **Purpose:** Display the current exception message (and optional traceback) with output truncation safeguards.
141
+ **Purpose:** Display the current exception message (and optional rich-formatted traceback) with output truncation safeguards.
142
142
  **Input:** `trace_back`, `length_limit`, optional `stream`.
143
- **Output:** Writes formatted error details to the target stream; flushes stdout/stderr.
143
+ **Output:** Writes formatted error details to the target stream using a `rich` console and flushes stdout/stderr.
144
144
  **Location:** `lib_cli_exit_tools/lib_cli_exit_tools.py`
145
145
 
146
146
  #### Function: _print_output
@@ -0,0 +1,209 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "7fb27b941602401d91542211134fc71a",
6
+ "metadata": {},
7
+ "source": [
8
+ "# lib_cli_exit_tools Quickstart\n",
9
+ "\n",
10
+ "Use this notebook to install the package, explore the CLI, and observe how rich-formatted tracebacks behave when you enable debugging output.\n"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "id": "acae54e37e7d407bbb7b55eff062a284",
16
+ "metadata": {},
17
+ "source": [
18
+ "## 1) Install latest from GitHub (default)\n"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "id": "9a63283cbaf04dbcab1f6479b197f3a8",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "# update pip and setuptools\n",
29
+ "import sys\n",
30
+ "\n",
31
+ "!{sys.executable} -m pip install --upgrade pip\n",
32
+ "!{sys.executable} -m pip install --upgrade setuptools\n",
33
+ "\n",
34
+ "# install lib_cli_exit_tools from GitHub (default)\n",
35
+ "!{sys.executable} -m pip install --upgrade git+https://github.com/bitranox/lib_cli_exit_tools.git"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "id": "8dd0d8092fe74a7c96281538738b07e2",
41
+ "metadata": {},
42
+ "source": [
43
+ "## Or: Install from PyPI (alternative)\n",
44
+ "Uncomment and run the cell below if you prefer the PyPI release.\n"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": null,
50
+ "id": "72eea5119410473aa328ad9291626812",
51
+ "metadata": {},
52
+ "outputs": [],
53
+ "source": [
54
+ "# !{sys.executable} -m pip install --upgrade lib_cli_exit_tools\n"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "markdown",
59
+ "id": "8edb47106e1a46a883d545849b8ab81b",
60
+ "metadata": {},
61
+ "source": [
62
+ "## 2) CLI: version and help\n"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "id": "10185d26023b46108eb7d9f57d49d2b3",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "!lib_cli_exit_tools --version\n",
73
+ "!lib_cli_exit_tools --help\n",
74
+ "!lib_cli_exit_tools info"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "markdown",
79
+ "id": "8763a12b2bbd4a93a75aff182afb95dc",
80
+ "metadata": {},
81
+ "source": [
82
+ "## 3) Demo command for failure handling\n",
83
+ "The helper below builds a tiny Click command that purposely raises an error so you can compare short messages with rich tracebacks.\n"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "execution_count": null,
89
+ "id": "7623eae2785240b9bd12b16a66d81610",
90
+ "metadata": {},
91
+ "outputs": [],
92
+ "source": [
93
+ "import click\n",
94
+ "from lib_cli_exit_tools.lib_cli_exit_tools import config, run_cli\n",
95
+ "\n",
96
+ "\n",
97
+ "@click.command()\n",
98
+ "def quickstart_fail() -> None:\n",
99
+ " \"\"\"Raise a demo error to exercise lib_cli_exit_tools.\"\"\"\n",
100
+ " raise RuntimeError(\"demo failure from Quickstart\")\n",
101
+ "\n",
102
+ "\n",
103
+ "def run_quickstart_demo(traceback_enabled: bool) -> int:\n",
104
+ " \"\"\"Execute the demo command with the desired traceback mode.\n",
105
+ "\n",
106
+ " The helper keeps tests deterministic by disabling signal handlers\n",
107
+ " in notebook contexts and resets global flags after execution.\n",
108
+ " \"\"\"\n",
109
+ "\n",
110
+ " original_flag = config.traceback\n",
111
+ " config.traceback = traceback_enabled\n",
112
+ " try:\n",
113
+ " return run_cli(quickstart_fail, argv=[], install_signals=False)\n",
114
+ " finally:\n",
115
+ " config.traceback = original_flag"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "markdown",
120
+ "id": "7cdc8c89c7104fffa095e18ddfef8986",
121
+ "metadata": {},
122
+ "source": [
123
+ "## 4) CLI failure with short message (default)\n",
124
+ "Tracebacks are suppressed by default; the CLI emits a concise summary and returns a deterministic exit code.\n"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": null,
130
+ "id": "b118ea5561624da68c537baed56e602f",
131
+ "metadata": {},
132
+ "outputs": [],
133
+ "source": [
134
+ "exit_code = run_quickstart_demo(False)\n",
135
+ "print(f\"Exit code: {exit_code}\")"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "markdown",
140
+ "id": "938c804e27f84196a10c8828c723f798",
141
+ "metadata": {},
142
+ "source": [
143
+ "## 5) CLI failure with rich traceback\n",
144
+ "Enable tracebacks to surface a full Rich-formatted stack trace for debugging.\n"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "execution_count": null,
150
+ "id": "504fb2a444614c0babb325280ed9130a",
151
+ "metadata": {},
152
+ "outputs": [],
153
+ "source": [
154
+ "import lib_cli_exit_tools\n",
155
+ "\n",
156
+ "try:\n",
157
+ " run_quickstart_demo(True)\n",
158
+ "except RuntimeError:\n",
159
+ " lib_cli_exit_tools.print_exception_message(trace_back=True)"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "markdown",
164
+ "id": "59bbdb311c014d738909a11f9e486628",
165
+ "metadata": {},
166
+ "source": [
167
+ "## 6) Library usage: exit codes and traceback formatting\n",
168
+ "Use the functional API to translate exceptions into exit codes and to opt in to rich tracebacks programmatically.\n"
169
+ ]
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "execution_count": null,
174
+ "id": "b43b363d81ae4b689946ece5c682cd59",
175
+ "metadata": {},
176
+ "outputs": [],
177
+ "source": [
178
+ "import lib_cli_exit_tools\n",
179
+ "\n",
180
+ "# Short message (default)\n",
181
+ "try:\n",
182
+ " raise FileNotFoundError(\"missing.txt\")\n",
183
+ "except Exception as exc:\n",
184
+ " exit_code = lib_cli_exit_tools.get_system_exit_code(exc)\n",
185
+ " lib_cli_exit_tools.print_exception_message(trace_back=False)\n",
186
+ " print(f\"Exit code would be: {exit_code}\")\n",
187
+ "\n",
188
+ "# Rich traceback\n",
189
+ "try:\n",
190
+ " raise ValueError(\"boom\")\n",
191
+ "except Exception:\n",
192
+ " lib_cli_exit_tools.print_exception_message(trace_back=True)"
193
+ ]
194
+ }
195
+ ],
196
+ "metadata": {
197
+ "kernelspec": {
198
+ "display_name": "Python 3",
199
+ "language": "python",
200
+ "name": "python3"
201
+ },
202
+ "language_info": {
203
+ "name": "python",
204
+ "version": "3"
205
+ }
206
+ },
207
+ "nbformat": 4,
208
+ "nbformat_minor": 5
209
+ }
@@ -3,7 +3,7 @@ class LibCliExitTools < Formula
3
3
 
4
4
  desc "CLI exit handling helpers: clean signals, exit codes, and error printing"
5
5
  homepage "https://github.com/bitranox/lib_cli_exit_tools"
6
- url "https://github.com/bitranox/lib_cli_exit_tools/archive/refs/tags/v1.2.0.tar.gz"
6
+ url "https://github.com/bitranox/lib_cli_exit_tools/archive/refs/tags/v1.3.0.tar.gz"
7
7
  k3cc316e7d0b09dd79e617cb3e91b14ee414b7e6695b108a326d9d3ccd08dd9"
8
8
  license "MIT"
9
9
 
@@ -17,7 +17,7 @@ k3cc316e7d0b09dd79e617cb3e91b14ee414b7e6695b108a326d9d3ccd08dd9"
17
17
 
18
18
  resource "rich-click" do
19
19
  url "https://files.pythonhosted.org/packages/29/c2/f08b5e7c1a33af8a115be640aa0796ba01c4732696da6d2254391376b314/rich_click-1.9.1.tar.gz"
20
- sha256 "4f2620589d7287f86265432e6a909de4f281de909fe68d8c835fbba49265d268"
20
+ ab87be0f5a4c171b43778922b5ed1f99611a0db5a4bf4d0f36770c18ef848d4"
21
21
  end
22
22
 
23
23
  def install
@@ -1,5 +1,5 @@
1
1
  {% set name = "lib_cli_exit_tools" %}
2
- {% set version = "1.2.0" %}
2
+ {% set version = "1.3.0" %}
3
3
 
4
4
  package:
5
5
  name: {{ name|lower }}
@@ -44,7 +44,7 @@
44
44
  {
45
45
  packages.default = pypkgs.buildPythonPackage {
46
46
  pname = "lib_cli_exit_tools";
47
- version = "1.2.0";
47
+ version = "1.3.0";
48
48
  pyproject = true;
49
49
  src = ../..;
50
50
  nativeBuildInputs = [ hatchlingVendor ];
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lib_cli_exit_tools"
3
- version = "1.2.0"
3
+ version = "1.3.0"
4
4
  description = "CLI exit handling helpers: clean signals, exit codes, and error printing"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -25,12 +25,15 @@ import os
25
25
  import signal
26
26
  import subprocess
27
27
  import sys
28
- import traceback
29
28
  from dataclasses import dataclass
30
29
  from types import FrameType
31
30
  from typing import Any, Callable, List, Literal, Optional, Protocol, Sequence, TextIO
32
31
 
33
32
  import rich_click as click
33
+ from rich_click import rich_click as rich_config
34
+ from rich.console import Console
35
+ from rich.text import Text
36
+ from rich.traceback import Traceback
34
37
 
35
38
  __all__ = [
36
39
  "config",
@@ -559,6 +562,33 @@ def _sysexits_mapping(exc: BaseException) -> int:
559
562
  return 1
560
563
 
561
564
 
565
+ def _build_console(stream: Optional[TextIO] = None) -> Console:
566
+ """Construct a Rich console that mirrors rich-click global settings.
567
+
568
+ Why:
569
+ Avoid duplicating console configuration whenever we need to emit
570
+ coloured output, ensuring help and error styling stay consistent.
571
+ Parameters:
572
+ stream: Optional target stream; defaults to :data:`sys.stderr`.
573
+ Returns:
574
+ Configured :class:`rich.console.Console` instance.
575
+ Side Effects:
576
+ None.
577
+ Examples:
578
+ >>> console = _build_console()
579
+ >>> isinstance(console, Console)
580
+ True
581
+ """
582
+
583
+ target_stream = stream or sys.stderr
584
+ return Console(
585
+ file=target_stream,
586
+ force_terminal=rich_config.FORCE_TERMINAL,
587
+ color_system=rich_config.COLOR_SYSTEM,
588
+ soft_wrap=True,
589
+ )
590
+
591
+
562
592
  def print_exception_message(
563
593
  trace_back: bool = config.traceback,
564
594
  length_limit: int = 500,
@@ -568,11 +598,12 @@ def print_exception_message(
568
598
 
569
599
  Why:
570
600
  Provide consistent, truncated error output when tracebacks are
571
- suppressed. This keeps CLI UX tidy while still surfacing useful
572
- information to the user.
601
+ suppressed while presenting syntax-highlighted tracebacks for
602
+ debugging when requested.
573
603
  Parameters:
574
- trace_back: When ``True`` append the full traceback to the message.
575
- length_limit: Maximum number of characters to emit.
604
+ trace_back: When ``True`` render a Rich traceback; otherwise emit a
605
+ single-line summary in red.
606
+ length_limit: Maximum number of characters to emit for summary output.
576
607
  stream: Target text stream; defaults to stderr.
577
608
  Returns:
578
609
  ``None``.
@@ -592,25 +623,36 @@ def print_exception_message(
592
623
 
593
624
  flush_streams()
594
625
 
595
- if stream is None:
596
- stream = sys.stderr
626
+ target_stream = stream or sys.stderr
597
627
 
598
628
  exc_info = sys.exc_info()[1]
599
629
  if exc_info is None:
600
630
  return
601
631
 
602
- if trace_back:
603
- exc_info_msg = "Traceback Information:\n" + traceback.format_exc()
604
- else:
605
- exc_info_msg = f"{type(exc_info).__name__}: {exc_info}"
632
+ _print_output(exc_info, "stdout", target_stream)
633
+ _print_output(exc_info, "stderr", target_stream)
606
634
 
607
- if len(exc_info_msg) > length_limit:
608
- exc_info_msg = f"{exc_info_msg[:length_limit]} ...[TRUNCATED at {length_limit} characters]"
635
+ console = _build_console(target_stream)
609
636
 
610
- _print_output(exc_info, "stdout", stream)
611
- _print_output(exc_info, "stderr", stream)
637
+ if trace_back:
638
+ tb_renderable = Traceback.from_exception(
639
+ type(exc_info),
640
+ exc_info,
641
+ exc_info.__traceback__,
642
+ show_locals=False,
643
+ )
644
+ console.print(tb_renderable)
645
+ else:
646
+ message = Text(
647
+ f"{type(exc_info).__name__}: {exc_info}",
648
+ style="bold red",
649
+ )
650
+ if len(message.plain) > length_limit:
651
+ truncated = f"{message.plain[:length_limit]} ... [TRUNCATED at {length_limit} characters]"
652
+ message = Text(truncated, style="bold red")
653
+ console.print(message)
612
654
 
613
- print(exc_info_msg, file=stream)
655
+ console.file.flush()
614
656
  flush_streams()
615
657
 
616
658
 
@@ -52,7 +52,7 @@ def test_print_exception_message_traceback_and_truncate() -> None:
52
52
  except Exception:
53
53
  print_exception_message(True, length_limit=40, stream=buf)
54
54
  out = buf.getvalue()
55
- assert "Traceback Information:" in out
55
+ assert "Traceback (most recent call last)" in out
56
56
 
57
57
  # Trigger truncation branch (traceback False) with tight limit
58
58
  buf = io.StringIO()
@@ -1,121 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "intro",
6
- "metadata": {},
7
- "source": [
8
- "# lib_cli_exit_tools Quickstart\n",
9
- "\n",
10
- "Install the package (from PyPI or GitHub), then try the CLI and API examples below."
11
- ]
12
- },
13
- {
14
- "cell_type": "markdown",
15
- "id": "github-title",
16
- "metadata": {},
17
- "source": [
18
- "## 1) Install latest from GitHub (default)"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": null,
24
- "id": "github-install",
25
- "metadata": {},
26
- "outputs": [],
27
- "source": [
28
- "# update pip and setuptools\n",
29
- "import sys\n",
30
- "\n",
31
- "!{sys.executable} -m pip install --upgrade pip\n",
32
- "!{sys.executable} -m pip install --upgrade setuptools\n",
33
- "\n",
34
- "# install lib_cli_exit_tools from GitHub (default)\n",
35
- "!{sys.executable} -m pip install --upgrade git+https://github.com/bitranox/lib_cli_exit_tools.git"
36
- ]
37
- },
38
- {
39
- "cell_type": "markdown",
40
- "id": "pypi-title",
41
- "metadata": {},
42
- "source": [
43
- "## Or: Install from PyPI (alternative)\n",
44
- "Uncomment and run the cell below if you prefer the PyPI release."
45
- ]
46
- },
47
- {
48
- "cell_type": "code",
49
- "execution_count": null,
50
- "id": "pypi-install",
51
- "metadata": {},
52
- "outputs": [],
53
- "source": [
54
- "# !{sys.executable} -m pip install --upgrade lib_cli_exit_tools\n"
55
- ]
56
- },
57
- {
58
- "cell_type": "markdown",
59
- "id": "cli-title",
60
- "metadata": {},
61
- "source": [
62
- "## 2) CLI: version and help"
63
- ]
64
- },
65
- {
66
- "cell_type": "code",
67
- "execution_count": null,
68
- "id": "cli-code",
69
- "metadata": {},
70
- "outputs": [],
71
- "source": [
72
- "!lib_cli_exit_tools --version\n",
73
- "!lib_cli_exit_tools --help\n",
74
- "!lib_cli_exit_tools info"
75
- ]
76
- },
77
- {
78
- "cell_type": "markdown",
79
- "id": "lib-title",
80
- "metadata": {},
81
- "source": [
82
- "## 3) Library usage: map exceptions to exit codes"
83
- ]
84
- },
85
- {
86
- "cell_type": "code",
87
- "execution_count": null,
88
- "id": "lib-code",
89
- "metadata": {},
90
- "outputs": [],
91
- "source": [
92
- "import lib_cli_exit_tools\n",
93
- "\n",
94
- "# show short messages\n",
95
- "lib_cli_exit_tools.config.traceback = False\n",
96
- "try:\n",
97
- " raise FileNotFoundError(\"missing.txt\")\n",
98
- "except Exception as e:\n",
99
- " code = lib_cli_exit_tools.get_system_exit_code(e) # 2 on POSIX\n",
100
- " lib_cli_exit_tools.print_exception_message() # prints: FileNotFoundError: missing.txt\n",
101
- " # In a real CLI you might exit with the code.\n",
102
- " # raise SystemExit(code)\n",
103
- " # In this notebook we just display it to keep execution green.\n",
104
- " print(f\"Exit code would be: {code}\")"
105
- ]
106
- }
107
- ],
108
- "metadata": {
109
- "kernelspec": {
110
- "display_name": "Python 3",
111
- "language": "python",
112
- "name": "python3"
113
- },
114
- "language_info": {
115
- "name": "python",
116
- "version": "3"
117
- }
118
- },
119
- "nbformat": 4,
120
- "nbformat_minor": 5
121
- }