Add CLI argument to print current settings

Fixes #2275
Refs #1762
This commit is contained in:
Justin Mayer 2018-10-23 17:57:37 +02:00
commit e81a284c39
2 changed files with 31 additions and 4 deletions

View file

@ -21,6 +21,12 @@ Settings are configured in the form of a Python module (a file). There is an
<https://github.com/getpelican/pelican/raw/master/samples/pelican.conf.py>`_ <https://github.com/getpelican/pelican/raw/master/samples/pelican.conf.py>`_
available for reference. available for reference.
To see a list of current settings in your environment, including both default
and any customized values, run the following command (append a specific
setting name as an argument to see the value for that one setting)::
pelican --print-settings
All the setting identifiers must be set in all-caps, otherwise they will not be All the setting identifiers must be set in all-caps, otherwise they will not be
processed. Setting values that are numbers (5, 20, etc.), booleans (True, processed. Setting values that are numbers (5, 20, etc.), booleans (True,
False, None, etc.), dictionaries, or tuples should *not* be enclosed in False, None, etc.), dictionaries, or tuples should *not* be enclosed in
@ -28,10 +34,9 @@ quotation marks. All other values (i.e., strings) *must* be enclosed in
quotation marks. quotation marks.
Unless otherwise specified, settings that refer to paths can be either absolute Unless otherwise specified, settings that refer to paths can be either absolute
or relative to the configuration file. or relative to the configuration file. The settings you define in the
configuration file will be passed to the templates, which allows you to use your
The settings you define in the configuration file will be passed to the settings to add site-wide content.
templates, which allows you to use your settings to add site-wide content.
Here is a list of settings for Pelican: Here is a list of settings for Pelican:

View file

@ -11,6 +11,7 @@ import re
import sys import sys
import time import time
import traceback import traceback
from pprint import pprint
import six import six
@ -319,6 +320,12 @@ def parse_arguments():
help='Relaunch pelican each time a modification occurs' help='Relaunch pelican each time a modification occurs'
' on the content files.') ' on the content files.')
parser.add_argument('--print-settings', dest='print_settings',
action='append', nargs='?', metavar='SETTING_NAME',
help='Print current configuration settings and exit. '
'Append a setting name as argument to see the value '
'for that specific setting only.')
parser.add_argument('--relative-urls', dest='relative_paths', parser.add_argument('--relative-urls', dest='relative_paths',
action='store_true', action='store_true',
help='Use relative urls in output, ' help='Use relative urls in output, '
@ -527,6 +534,21 @@ def main():
try: try:
pelican, settings = get_instance(args) pelican, settings = get_instance(args)
if args.print_settings:
# If no argument was given to --print-settings, print all settings
if args.print_settings[0] is None:
pprint(settings)
# An argument was given to --print-settings, so print that setting
else:
try:
pprint(settings[args.print_settings[0]])
except KeyError:
print("{} is not a recognized setting.".format(
args.print_settings[0]))
return 1
return 0
readers = Readers(settings) readers = Readers(settings)
reader_descs = sorted(set(['%s (%s)' % reader_descs = sorted(set(['%s (%s)' %
(type(r).__name__, (type(r).__name__,