Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added the `--overwrite` option for `inventory`
In addition, I've also added some error handling code to validate the
input before running the `inventory`
  • Loading branch information
chinyeungli committed Mar 16, 2016
1 parent bb9341e commit 71b4213
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion about_code_tool/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,27 @@ def cli(verbose, quiet):
@click.argument('output', nargs=1, required=True,
type=click.Path(exists=False, file_okay=True, writable=True,
dir_okay=False, resolve_path=True))
def inventory(location, output):
@click.option('--overwrite', count=True, help='Overwrites the output file if it exists')
def inventory(overwrite, location, output):
"""
Inventory components from an ABOUT file or a directory tree of ABOUT
files.
"""
click.echo('Running about-code-tool version ' + __version__)
# Check is the <OUTPUT> valid.
if os.path.exists(output) and not overwrite:
click.echo('ERROR: <output> file already exists. Select a different file name or use the --overwrite option.')
click.echo()
return
if not output.endswith('.csv'):
click.echo('ERROR: <output> must be a CSV file ending with ".csv".')
click.echo()
return
if not os.path.exists(output):
click.echo('ERROR: <output> does not exists. Please check and correct the <output>.')
click.echo()
return

click.echo('Collecting the inventory from location: ''%(location)s '
'and writing CSV output to: %(output)s' % locals())

Expand Down

0 comments on commit 71b4213

Please sign in to comment.