Skip to content

Commit

Permalink
Add CLI help strings
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Oct 2, 2021
1 parent 322c38f commit e1620eb
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/wireviz/wv_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,35 @@
import wireviz.wireviz as wv
from wireviz.wv_helper import open_file_read


@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):
format_codes = {'p': 'png', 's': 'svg', 't': 'tsv', 'c': 'csv', 'h': 'html', 'P': 'pdf'}

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:
return # print version number only and exit

# 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:
Expand Down

0 comments on commit e1620eb

Please sign in to comment.