From 77f668e553a14374ec1a18f3c29764dd060bc97e Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sat, 2 Oct 2021 13:04:38 +0200 Subject: [PATCH] Add CLI help strings --- src/wireviz/wv_cli.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/wireviz/wv_cli.py b/src/wireviz/wv_cli.py index cbc2e82..4bd0eba 100644 --- a/src/wireviz/wv_cli.py +++ b/src/wireviz/wv_cli.py @@ -8,14 +8,21 @@ from wireviz import APP_NAME, __version__ import wireviz.wireviz as wv from wireviz.wv_helper import open_file_read +format_codes = {'p': 'png', 's': 'svg', 't': 'tsv', 'c': 'csv', 'h': 'html', 'P': 'pdf'} -@click.command() -@click.argument('filepath', nargs=-1) -@click.option('-f', '--format', default='hpst') -@click.option('-p', '--prepend', default=None) -@click.option('-o', '--output-file', default=None) -@click.option('-V', '--version', is_flag=True, default=False) -def main(filepath, format, prepend, output_file, version): +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' +epilog += ', '.join([f'{key} ({value.upper()})' for key, value in format_codes.items()]) + +@click.command(epilog=epilog) +@click.argument('file', nargs=-1) +@click.option('-f', '--format', default='hpst', type=str, show_default=True, help='Output formats (see below).') +@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(f'{APP_NAME} {__version__}') if version: @@ -23,14 +30,13 @@ def main(filepath, format, prepend, output_file, version): # get list of files try: - _ = iter(filepath) + _ = iter(file) except TypeError: - filepaths = [filepath] + filepaths = [file] else: - filepaths = list(filepath) + filepaths = list(file) # determine output formats - format_codes = {'p': 'png', 's': 'svg', 't': 'tsv', 'c': 'csv', 'h': 'html', 'P': 'pdf'} return_types = [] for code in format: if code in format_codes: