Skip to content

Replace custom CLI with argparse - #83

Open
hugovk wants to merge 2 commits into
python:mainfrom
hugovk:argparse
Open

Replace custom CLI with argparse#83
hugovk wants to merge 2 commits into
python:mainfrom
hugovk:argparse

Conversation

@hugovk

@hugovk hugovk commented Aug 5, 2026

Copy link
Copy Markdown
Member

There's a lot of custom code for the CLI handling, which we can replace with argparse.

This saves us about 150 lines of code, and we get colour help, plus I've added backticks in some help messages for "code" formatting as well.

Right now, blurb has both subcommand and option versions of help and version:

blurb help
blurb -h
blurb --help

blurb version
blurb -V
blurb --version

This PR deprecates the subcommands in favour of the more ususal options.

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌈

Comment thread src/blurb/_cli.py
)

def add_subcommand(name: str, doc: str) -> argparse.ArgumentParser:
doc = doc.strip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't strip only strip the first line? I suggest using inpect.cleandoc instead.

Comment thread src/blurb/_cli.py
# Keep the legacy 'help' and 'version' subcommands working as aliases.
elif args[0] == 'help':
print(
"Warning: 'blurb help' is deprecated, use 'blurb --help' instead",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not warnings.warn(..., DeprecationWarning), that way we can suppress it.

Comment thread src/blurb/_cli.py
"Warning: 'blurb help' is deprecated, use 'blurb --help' instead",
file=sys.stderr,
)
args = [*args[1:2], '--help']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this allow extra arguments after --help?

Comment thread README.md



### blurb help

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest keeping at least a little note pointing to --help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants