Skip to content

Commit fbf43ee

Browse files
committed
sample pdb
1 parent 49e2779 commit fbf43ee

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 0.8.4dev
44

5+
* [Feature] Add aliased group to `cli.py`
6+
* [Feature] Add markdown utils
7+
* [Feature] Add sample jinja2 config
8+
* [Feature] Better structlog defaults
9+
* [Feature] Add `--pdb` to `cli.py`
10+
511
## 0.8.3 (2025-03-01)
612

713
* [Feature] Add `log.py`, `cli.py`, and `settings.py` modules to template

src/pkgmt/assets/template/src/package_name/cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Sample CLI (requires click, tested with click==8.1.3)
33
"""
44

5+
import sys
6+
57
import click
68

79

@@ -30,11 +32,39 @@ def resolve_command(self, ctx, args):
3032
return cmd.name, cmd, args
3133

3234

35+
# NOTE: this requires ipdb
36+
def pdb_option(f):
37+
"""Decorator to add --pdb option to any command."""
38+
39+
def callback(ctx, param, value):
40+
if value:
41+
42+
def excepthook(type_, value, traceback):
43+
import ipdb
44+
45+
ipdb.post_mortem(traceback)
46+
47+
sys.excepthook = excepthook
48+
49+
return click.option(
50+
"--pdb", is_flag=True, help="Drop into pdb on exceptions", callback=callback
51+
)(f)
52+
53+
3354
@click.group(cls=AliasedGroup)
3455
def cli():
3556
pass
3657

3758

59+
@cli.command()
60+
@pdb_option
61+
def test(pdb: bool): # NOTE: you must add pdb as an argument
62+
"""Test command for the pdb option"""
63+
x = 1
64+
y = 0
65+
print(x / y)
66+
67+
3868
@cli.command()
3969
@click.argument("name")
4070
def hello(name):

0 commit comments

Comments
 (0)