Ability to manually specify command_path for CLI Python modules
See original GitHub issueMy Python code must be run as a module. So the code where I define cli command is in __main__.py
, and I run the script with python -m foo
.
The problem is that Click displays the help instructions as:
Usage: __main__.py [OPTIONS] COMMAND [ARGS]...
But I would like:
Usage: python -m foo [OPTIONS] COMMAND [ARGS]...
I tried this:
@click.group(name='python -m foo')
def main():
pass
which as no effect,
and also this:
@click.group()
@click.pass_context
def main(ctx):
ctx.command_path = 'python -m foo'
which fails with AttributeError: can't set attribute
.
The ability to manually specify the command_path
is necessary to work with CLI Python modules or other particular scenarios.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
1. Command line and environment
path . Defines the user base directory , which is used to compute the path of the user site-packages directory and Distutils installation...
Read more >add PYTHONPATH during command line module run
Basically sys.path is a list with all the search paths for python modules. It is initialized by the interpreter. The content of PYTHONPATH...
Read more >Build Command-Line Interfaces With Python's argparse
This program implements a minimal CLI by manually processing the ... This module allows you to define the arguments and options that your ......
Read more >Configuring basic system settings Red Hat Enterprise Linux 8
Press the Automatic button, and select Manual from the displayed list. Press the Show button next to the protocol you want to configure...
Read more >Python Package Installation on Windows
How to manually install a Python package: Download the package and extract it into a local directory. 2a. If the package came with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone looking for the same behavior, here is a simple working example:
@davidism in the example you provided I was not able to guess what exactly was the imported
cli
.Thanks for your help. Is there an example of that in the docs?