Skip to content

Instantly share code, notes, and snippets.

@tomschr
Last active January 24, 2017 20:53
Show Gist options
  • Save tomschr/85ed8b8acfb70ccdcfbf533c674e00f4 to your computer and use it in GitHub Desktop.
Save tomschr/85ed8b8acfb70ccdcfbf533c674e00f4 to your computer and use it in GitHub Desktop.
Proof of concept of sdsc with docopt
#!/usr/bin/env python3
"""Checks a given DocBook XML file for stylistic errors
Usage:
sdsc [-h | --help]
sdsc [options] INPUTFILE [OUTPUTFILE]
Required arguments:
INPUTFILE the DocBook XML file to check for
OUTPUTFILE optional result file or stdout
Options:
-h, --help show this help message and exit
--version show version number and exit
-b, --bookmarklet open Web page that lets you install a bookmarklet to
manage style checker results
-s, --show show final report in $BROWSER, or default browser if
unset; not all browsers open report files correctly and
for some users, a text editor will open; in such cases,
set the BROWSER variable with: export BROWSER=/MY/BROWSER;
Chromium or Firefox will both do the right thing
--module writes name of current check module to stdout
--performance write performance measurements to stdout
--checkpatterns check formal validity of built-in regular expression
patterns
"""
from docopt import docopt
__proc__ = "sdsc"
__version__ = "1.0.0"
def parsecli(cliargs=None):
"""Parse CLI arguments with docopt
:param list cliargs: List of commandline arguments
:return: dictionary from docopt
:rtype: dict
"""
version = "%s %s" % (__package__, __version__)
args = docopt(__doc__, argv=cliargs, version=version)
return args
if __name__ == "__main__":
args = parsecli()
print(args)
# ./sdsc_docopt.py foo.xml
# {'--bookmarklet': False,
# '--checkpatterns': False,
# '--help': False,
# '--module': False,
# '--performance': False,
# '--show': False,
# '--version': False,
# 'INPUTFILE': 'foo.xml',
# 'OUTPUTFILE': None}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment