Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version option to show abi3audit version information #123

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions abi3audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,55 +175,72 @@ def main() -> None:
prog="abi3audit",
description="Scans Python extensions for abi3 violations and inconsistencies",
)
parser.add_argument(
version_group = parser.add_argument_group()
version_group.add_argument(
"-V",
"--version",
action="store_true",
help="show abi3audit version information",
)
main_group = parser.add_argument_group("main arguments")
main_group.add_argument(
Copy link
Member

Choose a reason for hiding this comment

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

I think this makes the parser a lot harder to follow -- could we use action='version' instead? That should handle everything automatically and avoid the need for separate arg groups.

For example:

parser.add_argument("-V", "--version", action='version', version=f"%(prog)s {__version__}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's much better, I didn't know that argparse had built in support for version display.

"specs",
metavar="SPEC",
nargs="+",
nargs="*",
help="the files or other dependency specs to scan",
)
parser.add_argument(
main_group.add_argument(
"--debug",
action="store_true",
help=(
"emit debug statements; this setting also overrides `ABI3AUDIT_LOGLEVEL` and "
"is equivalent to setting it to `debug`"
),
)
parser.add_argument(
main_group.add_argument(
"-v",
"--verbose",
action="store_true",
help=("give more output, including pretty-printed results for each audit step"),
)
parser.add_argument(
main_group.add_argument(
"-R", "--report", action="store_true", help="generate a JSON report; uses --output"
)
parser.add_argument(
main_group.add_argument(
"-o",
"--output",
type=argparse.FileType("w"),
default=sys.stdout,
help="the path to write the JSON report to (default: stdout)",
)
parser.add_argument(
main_group.add_argument(
"-s",
"--summary",
action="store_true",
help="always output a summary even if there are no violations/ABI version mismatches",
)
parser.add_argument(
main_group.add_argument(
"-S",
"--strict",
action="store_true",
help="fail the entire audit if an individual audit step fails",
)
parser.add_argument(
main_group.add_argument(
"--assume-minimum-abi3",
action=_PyVersionAction,
help="assumed abi3 version (3.x, with x>=2) if it cannot be detected",
)
args = parser.parse_args()

if args.version:
from . import __version__

print(f"abi3audit {__version__}")
sys.exit(0)
else:
if len(args.specs) == 0:
console.log("[red]:thumbs_down: no input specs")

if args.debug:
logging.root.setLevel("DEBUG")

Expand Down
Loading