[Python] create and publish commandline using click

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to click command. I am trying to write on terminal something like: hello project template list which should then call a function to simply read a json file and print the content on the terminal. I have figured out the way to do so using only hello list but I want to know how hello project template list could be done. I have tried the below code:

    import click
    import json

    @click.group()
    def cli():
    pass

    @cli.command(name='to print something')
    def project():
    # click.echo('hello project template list')
    with open('template.json', ) as f:
    data = json.load(f)
    for i in data['project_template']:
    print()
    print("Template name: ", i['template_name'])
    print("GitHub location: ", i['github_location'])
    print("Project Description: ", i['project_description'])
    print()


    if __name__ == "__main__":
    cli()

    Continue reading...

Compartilhe esta Página