-1

Description: User will need to install my utility and run two different commands from it: command_1 and command_2

for this in setup.py I used this syntax:

    entry_points={
        'console_scripts': [
            'command_1 = src.cli:function_command_1',
            'command_2 = src.cli:function_command_2',
        ]

after user execute: pip install my_module he can use two separate commands in comand line;

for example User can run:

command_1 --parameter_1='p1' --parameter_2='p2'

Problem:

What if my module executes several commands, not a single one? For example:

my_module command_1 --parameter_1='p1' --parameter_2='p2'
my_module command_2 --parameter_1='p3' --parameter_2='p4'
...
my_module command_15 --parameter_1='p15'

There is a solution to use click to have different single commands for app: How can I split my Click commands, each with a set of sub-commands, into multiple files?

did anyone had a similar challenge, if no, any advice?

Thanks to everyone in advance

  • 1
    Is there a reason why you don't want to use [Click](https://click.palletsprojects.com/en/7.x/)? [Typer](https://typer.tiangolo.com/) is another option which might be even easier to use. Do you have a requirement not to use external packages? – daviewales Apr 20 '21 at 10:03
  • 1
    If you want to do this using the standard library, you would use [argparse](https://docs.python.org/3/library/argparse.html). Here are some related questions similar to what you are trying to do: [argparse-with-required-subcommands](https://stackoverflow.com/questions/18282403/argparse-with-required-subcommands) [get-selected-subcommand-with-argparse](https://stackoverflow.com/questions/4575747/get-selected-subcommand-with-argparse) – daviewales Apr 20 '21 at 10:13
  • Typer uses Click internaly, but I don't see much benefits from Typer, at least I didn't found what I want. – Pulia Zlaya Apr 23 '21 at 08:03
  • 1
    Could give a bit more detail about your requirements? From your question, it sounds like you need a script with [two subcommands](https://typer.tiangolo.com/#an-example-with-two-subcommands). Could you explain why that example isn't what you need? – daviewales Apr 25 '21 at 09:25
  • @daviewales, I want to have an utility that has several commands, alike: -$ utility_name command_1 --par1='asd' --par2='asd' – Pulia Zlaya Apr 28 '21 at 08:35
  • 1
    Actualy, this is what I needed: https://stackoverflow.com/questions/54087479/how-to-set-entry-point-for-console-script-with-multiple-command-groups-for-pytho – Pulia Zlaya May 07 '21 at 12:53

1 Answers1

0

I found that argparse doing this: https://stackoverflow.com/a/28908244/5945646

The click does not provide this functionality directly

UPDATE:

Actualy, it does: You have to use click groups, and point console command in setup.py to file with click command, and after install you will have module command and subcommands -

How to set entry point for console script with multiple command groups for Python Click?