Add CLI help strings

This commit is contained in:
Daniel Rojas 2021-10-02 13:04:38 +02:00
parent 19481b291b
commit 77f668e553

View File

@ -8,14 +8,21 @@ from wireviz import APP_NAME, __version__
import wireviz.wireviz as wv import wireviz.wireviz as wv
from wireviz.wv_helper import open_file_read from wireviz.wv_helper import open_file_read
format_codes = {'p': 'png', 's': 'svg', 't': 'tsv', 'c': 'csv', 'h': 'html', 'P': 'pdf'}
@click.command() epilog = 'The -f or --format option accepts a string containing one or more of the following characters to specify which file types to output:\n'
@click.argument('filepath', nargs=-1) epilog += ', '.join([f'{key} ({value.upper()})' for key, value in format_codes.items()])
@click.option('-f', '--format', default='hpst')
@click.option('-p', '--prepend', default=None) @click.command(epilog=epilog)
@click.option('-o', '--output-file', default=None) @click.argument('file', nargs=-1)
@click.option('-V', '--version', is_flag=True, default=False) @click.option('-f', '--format', default='hpst', type=str, show_default=True, help='Output formats (see below).')
def main(filepath, format, prepend, output_file, version): @click.option('-p', '--prepend', default=None, type=Path, help='YAML file to prepend to the input file (optional).')
@click.option('-o', '--output-file', default=None, type=Path, help='File name (without extension) to use for output, if different from input file name.')
@click.option('-V', '--version', is_flag=True, default=False, help=f'Output {APP_NAME} version and exit.')
def main(file, format, prepend, output_file, version):
"""
Parses the provided FILE and generates the specified outputs.
"""
print() print()
print(f'{APP_NAME} {__version__}') print(f'{APP_NAME} {__version__}')
if version: if version:
@ -23,14 +30,13 @@ def main(filepath, format, prepend, output_file, version):
# get list of files # get list of files
try: try:
_ = iter(filepath) _ = iter(file)
except TypeError: except TypeError:
filepaths = [filepath] filepaths = [file]
else: else:
filepaths = list(filepath) filepaths = list(file)
# determine output formats # determine output formats
format_codes = {'p': 'png', 's': 'svg', 't': 'tsv', 'c': 'csv', 'h': 'html', 'P': 'pdf'}
return_types = [] return_types = []
for code in format: for code in format:
if code in format_codes: if code in format_codes: