mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Use rich.console with printing settings
This commit is contained in:
parent
1cd7dd6a28
commit
a168470f29
1 changed files with 12 additions and 5 deletions
|
|
@ -228,26 +228,33 @@ class Pelican:
|
||||||
|
|
||||||
class PrintSettings(argparse.Action):
|
class PrintSettings(argparse.Action):
|
||||||
def __call__(self, parser, namespace, values, option_string):
|
def __call__(self, parser, namespace, values, option_string):
|
||||||
instance, settings = get_instance(namespace)
|
init_logging(name=__name__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
instance, settings = get_instance(namespace)
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical("%s: %s", e.__class__.__name__, e)
|
||||||
|
console.print_exception()
|
||||||
|
sys.exit(getattr(e, 'exitcode', 1))
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
# One or more arguments provided, so only print those settings
|
# One or more arguments provided, so only print those settings
|
||||||
for setting in values:
|
for setting in values:
|
||||||
if setting in settings:
|
if setting in settings:
|
||||||
# Only add newline between setting name and value if dict
|
# Only add newline between setting name and value if dict
|
||||||
if isinstance(settings[setting], dict):
|
if isinstance(settings[setting], (dict, tuple, list)):
|
||||||
setting_format = '\n{}:\n{}'
|
setting_format = '\n{}:\n{}'
|
||||||
else:
|
else:
|
||||||
setting_format = '\n{}: {}'
|
setting_format = '\n{}: {}'
|
||||||
print(setting_format.format(
|
console.print(setting_format.format(
|
||||||
setting,
|
setting,
|
||||||
pprint.pformat(settings[setting])))
|
pprint.pformat(settings[setting])))
|
||||||
else:
|
else:
|
||||||
print('\n{} is not a recognized setting.'.format(setting))
|
console.print('\n{} is not a recognized setting.'.format(setting))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# No argument was given to --print-settings, so print all settings
|
# No argument was given to --print-settings, so print all settings
|
||||||
pprint.pprint(settings)
|
console.print(settings)
|
||||||
|
|
||||||
parser.exit()
|
parser.exit()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue