From a1d3724b8dc96fd5cdc296fe85455e6bf4f66d89 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 11 Dec 2022 10:54:03 +0100 Subject: [PATCH] Added [-v|--verbose] and --version options to the command line. --- platypush/__init__.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/platypush/__init__.py b/platypush/__init__.py index f31b198c71..c112d0f13e 100644 --- a/platypush/__init__.py +++ b/platypush/__init__.py @@ -61,6 +61,7 @@ class Daemon: no_capture_stdout=False, no_capture_stderr=False, redis_queue=None, + verbose=False, ): """ Constructor @@ -76,6 +77,7 @@ class Daemon: no_capture_stderr -- Set to true if you want to disable the stderr capture by the logging system redis_queue -- Name of the (Redis) queue used for dispatching messages (default: platypush/bus). + verbose -- Enable debug/verbose logging, overriding the stored configuration (default: False). """ if pidfile: @@ -86,7 +88,10 @@ class Daemon: self.redis_queue = redis_queue or self._default_redis_queue self.config_file = config_file Config.init(self.config_file) - logging.basicConfig(**(Config.get('logging') or {})) + logging_conf = Config.get('logging') or {} + if verbose: + logging_conf['level'] = logging.DEBUG + logging.basicConfig(**logging_conf) redis_conf = Config.get('backend.redis') or {} self.bus = RedisBus( @@ -119,6 +124,21 @@ class Daemon: default=None, help=cls.config_file.__doc__, ) + parser.add_argument( + '--version', + dest='version', + required=False, + action='store_true', + help="Print the current version and exit", + ) + parser.add_argument( + '--verbose', + '-v', + dest='verbose', + required=False, + action='store_true', + help="Enable verbose/debug logging", + ) parser.add_argument( '--pidfile', '-P', @@ -157,12 +177,18 @@ class Daemon: ) opts, args = parser.parse_known_args(args) + + if opts.version: + print(__version__) + sys.exit(0) + return cls( config_file=opts.config, pidfile=opts.pidfile, no_capture_stdout=opts.no_capture_stdout, no_capture_stderr=opts.no_capture_stderr, redis_queue=opts.redis_queue, + verbose=opts.verbose, ) def on_message(self):