Added [-v|--verbose] and --version options to the command line.

This commit is contained in:
Fabio Manganiello 2022-12-11 10:54:03 +01:00
parent cf9d34d38e
commit a1d3724b8d
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -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):