Just get rid of the group since you don't want it. Use a command directly like:

Code:

import click
import sys

@click.command()
@click.option('--version', is_flag=True, default=False,
              help='Prints out pyisg package version being used')
@click.option('--readpower', type=str, default="",
              help='Path of the csv file which is to be read)')
def cli(version, readpower):
    """
    This utility is used to convert a CSV file to JSON file
    """
    if version:
        click.echo("This is version 1.0 software")
        sys.exit()

    if readpower != '':
        click.echo("reading power {}".format(readpower))

Test Code:

if __name__ == "__main__":
    cli('--readpower=3'.split())
    cli('--version'.split())
Answer from Stephen Rauch on Stack Overflow
🌐
Real Python
realpython.com › python-click
Click and Python: Build Extensible and Composable CLI Apps – Real Python
March 18, 2026 - You use two decorators on top of this function. The @click.command decorator declares hello() as a Click command with the name "hello". The @click.version_option decorator sets the CLI app’s version and name.
🌐
AssemblyAI
assemblyai.com › blog › the-definitive-guide-to-python-click
The Definitive Guide to Python Click | AssemblyAI
July 28, 2021 - Click, or “Command Line Interface ... main points of Python Click are arbitrary nesting of commands, automatic help page generation, and supporting lazy loading of subcommands at runtime....
🌐
Maurice Brg
mauricebrg.com › article › 2020 › 08 › advanced_cli_structures_with_python_and_click.html
Advanced CLI structures with Python and Click | Maurice Borgmeier
August 17, 2020 - We can then add commands to this group in two ways: Use the @click.command decorator on a function to define our regular command and later run cli.add_command(add) to add the command to our group.
🌐
KDnuggets
kdnuggets.com › building-command-line-apps-in-python-with-click
Building Command Line Apps in Python with Click - KDnuggets
October 4, 2024 - In Click, arguments are positional parameters you must provide in the order specified by the command. Unlike options, which are specified using flags (like --name), arguments are required and do not use double dashes (--).
🌐
Snyk
snyk.io › advisor › click › functions › click.command
How to use the click.command function in click | Snyk
@click.command("connect", short_help="Start a worker node.") @click.option( "--address", help="IP address of the master node.", required=True) @click.option( "--cpu_num", type=int, help="Set number of cpu manually.
🌐
Readthedocs
pocoo-click.readthedocs.io › en › latest › commands
Commands and Groups - the Click Documentation
This behavior can be changed by passing invoke_without_command=True to a group. In that case, the callback is always invoked instead of showing the help page. The context object also includes information about whether or not the invocation would go to a subcommand. ... @click.group(invoke_without_command=True) @click.pass_context def cli(ctx): if ctx.invoked_subcommand is None: click.echo('I was invoked without subcommand') else: click.echo('I am about to invoke %s' % ctx.invoked_subcommand) @cli.command() def sync(): click.echo('The subcommand')
Top answer
1 of 2
1

Just get rid of the group since you don't want it. Use a command directly like:

Code:

import click
import sys

@click.command()
@click.option('--version', is_flag=True, default=False,
              help='Prints out pyisg package version being used')
@click.option('--readpower', type=str, default="",
              help='Path of the csv file which is to be read)')
def cli(version, readpower):
    """
    This utility is used to convert a CSV file to JSON file
    """
    if version:
        click.echo("This is version 1.0 software")
        sys.exit()

    if readpower != '':
        click.echo("reading power {}".format(readpower))

Test Code:

if __name__ == "__main__":
    cli('--readpower=3'.split())
    cli('--version'.split())
2 of 2
0

Click is actually doing what it is supposed to do. You created a group cli and added the single command read_csv. So click needs to know the command to know what to invoke because there could possibly be more and even nested commands. You could create a standalone click command read_csvand register it in your setup.py file like so:

# app.py
import click

# as a standalone command
@click.command()
@click.option('--readpower', type=str, default="")
def read_csv(readpower):
    click.echo("doing stuff...")
    if readpower:
        click.echo("reading {}...".format(readpower))

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

@cli.command()
def do_stuff():
    click.echo("doing stuff...")

# as a subcommand in a group
@cli.command()
@click.option('--readpower', type=str, default="")
def read_csv(readpower):
    click.echo("doing something...")
    if readpower:
        click.echo("reading {}...".format(readpower))

And the setup:

# setup.py
from setuptools import setup

setup(
    name='app',
    version='0.1',
    py_modules=['app'],
    install_requires=['Click'],
    entry_points='''
        [console_scripts]
        read_csv=app:read_csv
        cli=app:cli
    ''',
)

So you can set multiple entry points to your application and mix multiple standalone commands with grouped (and even possibly nested) commands.

🌐
Click Documentation
click.palletsprojects.com
Welcome to Click — Click Documentation (8.5.x)
It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API. ... import click @click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name', prompt='Your name', help='The person to greet.') def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo(f"Hello {name}!") if __name__ == '__main__': hello()
Find elsewhere
🌐
ZetCode
zetcode.com › python › click
Python click - creating command line interfaces
January 29, 2024 - The commands are basic building blocks of an application. Click defines commands through decorators. They are created with the click.command decorator. Values are passed to the commands via options or arguments. Options are added with the click.option decorator, arguments with the click.argument.
🌐
Click Documentation
click.palletsprojects.com › en › stable › commands
Advanced Groups and Context — Click Documentation (8.5.x)
Commands can also ask for the context to be passed by marking themselves with the pass_context() decorator. In that case, the context is passed as first argument. The context can also carry a program specified object that can be used for the program’s purposes. What this means is that you can build a script like this: @click.group() @click.option('--debug/--no-debug', default=False) @click.pass_context def cli(ctx, debug): # ensure that ctx.obj exists and is a dict (in case `cli()` is called # by means other than the `if` block below) ctx.ensure_object(dict) ctx.obj['DEBUG'] = debug @cli.command() @click.pass_context def sync(ctx): click.echo(f"Debug is {'on' if ctx.obj['DEBUG'] else 'off'}") if __name__ == '__main__': cli(obj={})
🌐
Readthedocs
pocoo-click.readthedocs.io › en › latest › advanced
Advanced Patterns - the Click Documentation
If an option or argument is split up on the command line into multiple places because it is repeated – for instance, --exclude foo --include baz --exclude bar – the callback will fire based on the position of the first option. In this case, the callback will fire for exclude and it will be passed both options (foo and bar), then the callback for include will fire with baz only. Note that even if a parameter does not allow multiple versions, Click will still accept the position of the first, but it will ignore every value except the last.
🌐
Better Stack
betterstack.com › community › guides › scaling-python › click-explained
Creating composable CLIs with click in Python | Better Stack Community
Start by creating a new directory and setting up a virtual environment: ... Create a new file called cli.py in the root of your project directory, and populate it with the following contents: ... import click @click.command() def hello(): """Simple ...
🌐
Digitalk
digitalk.tech › blog › python-click-or-how-to-write-professional-cli-applications
Mndwrk Blog - Python click or how to write professional CLI applications
June 17, 2022 - Let’s study the above example and see what is happening. The first thing one might notice is that click uses decorators heavily. That is because when we define a command (represented by the function main), the click subsystem will call this function with the options and arguments passed to it.
🌐
Readthedocs
pymbook.readthedocs.io › en › latest › click.html
Building command line applications with Click — Python for you and me 0.5.beta1 documentation
In a command line tool, we sometimes want to have a boolean option. If the option is provided then do something, if not provided, then do something else. In our example, we will call the flag as –verbose, it is provided, then we will print some extra text. import click @click.command() @click.option('--verbose', is_flag=True, help="Will print verbose messages.") def cli(verbose): if verbose: click.echo("We are in the verbose mode.") click.echo("Hello World")
🌐
Click Documentation
click.palletsprojects.com › en › stable › commands-and-groups
Basic Commands, Groups, Context — Click Documentation (8.5.x)
Commands and Groups are the building blocks for Click applications. Command wraps a function to make it into a cli command. Group wraps Commands and Groups to make them into applications.
🌐
Paiml
paiml.com › docs › home › books › python-command-line-tools › chapter06-use-advanced-click-features
Chapter06 Use Advanced Click Features | Pragmatic AI Labs and Solutions
To dynamically load jobs that are present in the remote Jenkins server as sub-commands, a custom class needs to get in place and handle the loading. Click allows this with the click.MultiCommand class and this is how the implementation looks for this case:
🌐
PyPI
pypi.org › project › click
click · PyPI
2 weeks ago - It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API. ... import click @click.command() @click.option("--count", default=1, help="Number of greetings.") @click.option("--name", prompt="Your name", help="The person to greet.") def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for _ in range(count): click.echo(f"Hello, {name}!") if __name__ == '__main__': hello()
🌐
GeeksforGeeks
geeksforgeeks.org › click-module-in-python-making-awesome-command-line-utilities
Click Module in Python | Making awesome Command Line Utilities - GeeksforGeeks
March 14, 2019 - It is kind of strange that with all the advancements in UI/UX technologies, very few people know that there are to create beautiful command line interfaces too. Ever wanted to create a command line tool yourself that is actually very user-friendly, efficient and easy to use? Well, click is a Python Package that does just that.
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › click-command-prompt
Click Command Prompt - an overview | ScienceDirect Topics
At the command prompt, type ldifde -i -v -f BitLockerTPMSchema Extension.ldf -c “DC=X” “distinguished name of your domain” -k -j. Do not forget the period at the end of the command! ... Now we'll show you how to turn on BitLocker for data volumes. ... Log on as an administrator. ... Click Start, click All Programs, click Accessories, and then click Command Prompt.