3

I have a function with click decorators. The entire purpose of the function is to add a CLI option to the work being done by the tq_oex_interchange class.

@click.command()
@click.option('-input_file', help='The input file to process')
@click.option('-output_file', help='The output file to create')
@click.option('-part_num_col', help='The column containing the part numbers')
@click.option('-summate_cols', help='The columns to summate')
def run(input_file, output_file, part_num_col, summate_cols):
    from re import split
    summate_cols = [int(i) for i in split(',', summate_cols)]
    part_num_col = int(part_num_col)
    teek = tq_oex_interchange()
    click.echo("Working...")
    teek.scan_file(input_file, output_file, part_num_col, summate_cols)

However, when i execute my script with the command

python tq_oex.py -input_file C:\Users\barnej78\Desktop\test_0.csv -output_file C:\Users\barnej78\Desktop\cmd.csv -part_num_col 3 -summate_cols 5,6

Nothing happens, not even the click echo is executed.

Additionally,

python tq_oex.py --help

Also doesn't do anything.

There is no error or exception output for any of these command.

What am I doing wrong?

1
  • Is this the entire script? Commented Mar 25, 2017 at 22:33

1 Answer 1

2

Have you been able to successfully run the example code from here?

http://click.pocoo.org/5/

I'd start with that and make sure it works. Then write a test for it, using the Click test docs:

http://click.pocoo.org/5/testing/

That way when you start tweaking it, you can runs tests to see what breaks...

With Click applications, I often start simple, with one argument, and then add another to make sure it still works:

@click.command()
@click.argument('input_file')
def run_files(input_file):
    click.echo(input_file)

Then add one option to this:

@click.command()
@click.argument('input_file')
@click.option('--output_file', help='The output file to create')
def run_files(input_file, output_file):
    click.echo(input_file, output_file)

I like to set defaults as well, for debugging purposes:

def run_files(input_file='/path/to/input_file',
              output_file='/path/to/output_file'):
    click.echo(input_file, output_file)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.