Using click to pass an integer in a nested function

Viewed 63

I am using click (v. 8.1.3) to create a CLI for a nested function that will take an integer as an input. This is my MWE:

from datetime import date

@click.command()
@click.argument('year', type=click.INT, default=date.today().year)
def this_year(year):
    
    print(f'The year is {year}')
    
    return year

@click.command()
@click.argument('year', type=click.INT, default=date.today().year)
def ask_next_year(year):

    next_year = this_year(year) + 1
    print(f'The next year is year is {next_year}')

    return next_year

if __name__ == '__main__':
    ask_next_year()

However, I get the error that TypeError: 'int' object is not iterable. If I comment the first decorator of this_year (@click.command()), I get no error, but then of course the function is not accessible through the CLI. I have read the documentation, but I can't find what I am doing wrong.

0 Answers
Related