From 6e7eca8a2f4173e685bc5f79e32d54a5da7229e5 Mon Sep 17 00:00:00 2001 From: Ashish Bijlani Date: Thu, 26 Jan 2023 11:38:51 -0600 Subject: [PATCH] Add support to dump version info (feature request) Signed-off-by: Ashish Bijlani --- packj/__init__.py | 1 + packj/main.py | 6 ++++++ packj/options.py | 7 +++++-- setup.py | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packj/__init__.py b/packj/__init__.py index e69de29..9306ea7 100644 --- a/packj/__init__.py +++ b/packj/__init__.py @@ -0,0 +1 @@ +__version__ = "0.14" diff --git a/packj/main.py b/packj/main.py index 6a584a4..0f19da4 100644 --- a/packj/main.py +++ b/packj/main.py @@ -20,6 +20,12 @@ def main(config:str='.packj.yaml'): args = opts.args() assert args, 'Failed to get cmdline args!' + # version request + if args.ver and not args.cmd: + from packj import __version__ + print(__version__) + exit(1) + # configuration file if not os.path.exists(config): config = os.path.expanduser(os.path.join('~', f'{config}')) diff --git a/packj/options.py b/packj/options.py index ce67c4b..5f74d3f 100644 --- a/packj/options.py +++ b/packj/options.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +from packj import __version__ class Options(): __args = None @@ -9,10 +10,12 @@ def args(self): return self.__args def __init__(self, argv): - parser = argparse.ArgumentParser(prog='packj v0.1', + parser = argparse.ArgumentParser(prog=f'packj {__version__}', usage='main [options] args', description='Packj flags malicious/risky open-source packages') - subparsers = parser.add_subparsers(title='actions', dest='cmd', help='Command (e.g. audit, sandbox)') + subparsers = parser.add_subparsers(title='actions', dest='cmd', help='Command (e.g. auth, audit, sandbox)') + + parser.add_argument('-v', '--version', help='Dump tool version', dest="ver", action='store_true') ############################# # Authenticate sub-command diff --git a/setup.py b/setup.py index e3ffa81..70e3ce7 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,8 @@ import shutil import os, sys, subprocess +from packj import __version__ + here = os.path.abspath(os.path.dirname(__file__)) # package descr @@ -76,7 +78,7 @@ def run(self): data_files = [ (os.path.expanduser('~'), ['.packj.yaml']), ], - version = '0.13', + version = __version__, license='GNU AGPLv3', description = 'Packj flags "risky" open-source packages in your software supply chain', long_description=long_description,