-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The file cli.py is not created with a small example for the cli option defined by the user #122
Comments
A very simple example for argparse could be inspired by this snippet: import argparse
import os
import sys
from {{ cookiecutter.package_slug }} import __version__
class CustomHelpFormatter(argparse.RawTextHelpFormatter):
"""Formatter for generating usage messages and argument help strings.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""
def __init__(
self,
prog,
indent_increment=2,
max_help_position=4,
width=None,
**kwargs,
):
super().__init__(
prog,
indent_increment=indent_increment,
max_help_position=max_help_position,
width=width,
**kwargs,
)
def get_args():
"""Return the arguments for the CLI."""
parser = argparse.ArgumentParser(
prog='{{ coockiecutter.project_slug }}',
description=('{{ coockiecutter.project_name }}'),
epilog=(
'If you have any problem, open an issue at: '
'{{ cookiecutter.project_url }}'
),
add_help=True,
formatter_class=CustomHelpFormatter,
)
parser.add_argument(
'--version',
action='store_true',
help='Show the version of the installed {{ cookiecutter.project_name }} tool.',
)
return parser
def show_version():
"""Show the version for the application."""
print(__version__)
def app():
"""Run the application."""
args_parser = get_args()
args = args_parser.parse_args()
if args.version:
return show_version() of course, this one uses single quote, but the real implementation should check if it is blue or black and set a variable QUOTE (in the template), and use it instead of hard coded single quote |
Additionally, we need to have something like this inside the pyproject.toml:
just if the CLI tool was selected by the user. this new section could be defined after the section |
@xmnlab Any code suggestions for Click. I have seen this, but I don't really know which one could be useful, I don't know much about it. |
I would just use the chatgpt for converting the current one to click |
Summary
The file cli.py is not created with a small example for the cli option defined by the user
Additional Information
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: