flesh out CLI options and add --loglevel option

This commit is contained in:
Martin A. Brown 2016-02-22 17:10:45 -08:00
parent 7486a26cc3
commit f6eedfcb7b
2 changed files with 44 additions and 2 deletions

View File

@ -3,17 +3,49 @@
from __future__ import absolute_import, division, print_function
from tldp.utils import logger, isdirectory
import logging
from tldp.utils import logger, isdirectory, isloglevel
from tldp.cascadingconfig import CascadingConfig, DefaultFreeArgumentParser
import tldp.doctypes
status_types = ['all',
'sources',
'outputs',
'new',
'broken',
'orphaned',
'published',
'stale',
]
def collectconfiguration(argv):
tag = 'ldptool'
argparser = DefaultFreeArgumentParser()
argparser.add_argument('--build',
'-b',
nargs='*', default=None, type=str,
help='build LDP documentation')
argparser.add_argument('--list',
'-l',
nargs='?', default=None, type=str,
choices=status_types,
help='list elements of LDP publication system')
argparser.add_argument('--status',
'-t',
action='store_true', default=False,
help='produce a detailed status report of documents')
argparser.add_argument('--all',
'-a',
action='store_true', default=False,
help='process all documents (list, build or status)')
argparser.add_argument('--loglevel',
'-L',
default=logging.ERROR, type=isloglevel,
help='set the loglevel')
argparser.add_argument('--sourcedir', '--source-dir', '--source-directory',
'-s',
'-i',
action='append', default=None, type=isdirectory,
help='a directory containing LDP source documents')
argparser.add_argument('--pubdir', '--output', '--outputdir', '--outdir',

View File

@ -33,6 +33,16 @@ def firstfoundfile(locations):
return None
def isloglevel(l):
try:
level = int(l)
except ValueError:
level = getattr(logging, l, None)
if level is None:
level = logging.ERROR
return level
def isdirectory(d):
if os.path.exists(d):
return d