cli: add short names for options (#81)

This commit is contained in:
Sina Atalay 2024-05-28 19:05:03 +03:00
parent a5b2f8f240
commit c983a10855
1 changed files with 30 additions and 11 deletions

View File

@ -37,6 +37,8 @@ app = typer.Typer(
rich_markup_mode="rich", rich_markup_mode="rich",
add_completion=False, add_completion=False,
invoke_without_command=True, # to make rendercv --version work invoke_without_command=True, # to make rendercv --version work
no_args_is_help=True,
context_settings={"help_option_names": ["-h", "--help"]},
) )
@ -106,7 +108,7 @@ def information(text: str):
Args: Args:
text (str): The text of the information message. text (str): The text of the information message.
""" """
print(f"[bold green]{text}") print(f"[yellow]{text}")
def get_error_message_and_location_and_value_from_a_custom_error( def get_error_message_and_location_and_value_from_a_custom_error(
@ -428,7 +430,7 @@ class LiveProgressReporter(rich.live.Live):
"""End the live progress reporting.""" """End the live progress reporting."""
self.overall_progress.update( self.overall_progress.update(
self.overall_task_id, self.overall_task_id,
description=f"[bold green]{self.end_message}", description=f"[yellow]{self.end_message}",
) )
@ -521,8 +523,8 @@ def parse_data_model_override_arguments(
@app.command( @app.command(
name="render", name="render",
help=( help=(
"Render a YAML input file. Example: [bold green]rendercv render" "Render a YAML input file. Example: [yellow]rendercv render"
" John_Doe_CV.yaml[/bold green]" " John_Doe_CV.yaml[/yellow]. Details: [cyan]rendercv render --help[/cyan]"
), ),
# allow extra arguments for updating the data model: # allow extra arguments for updating the data model:
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}, context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
@ -530,12 +532,13 @@ def parse_data_model_override_arguments(
@handle_exceptions @handle_exceptions
def cli_command_render( def cli_command_render(
input_file_name: Annotated[ input_file_name: Annotated[
str, str, typer.Argument(help="Name of the YAML input file.")
typer.Argument(help="Name of the YAML input file."),
], ],
use_local_latex_command: Annotated[ use_local_latex_command: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--use-local-latex-command",
"-use",
help=( help=(
"Use the local LaTeX installation with the given command instead of the" "Use the local LaTeX installation with the given command instead of the"
" RenderCV's TinyTeX." " RenderCV's TinyTeX."
@ -545,36 +548,48 @@ def cli_command_render(
output_folder_name: Annotated[ output_folder_name: Annotated[
str, str,
typer.Option( typer.Option(
"--output-folder-name",
"-o",
help="Name of the output folder.", help="Name of the output folder.",
), ),
] = "rendercv_output", ] = "rendercv_output",
latex_path: Annotated[ latex_path: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--latex-path",
"-latex",
help="Copy the LaTeX file to the given path.", help="Copy the LaTeX file to the given path.",
), ),
] = None, ] = None,
pdf_path: Annotated[ pdf_path: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--pdf-path",
"-pdf",
help="Copy the PDF file to the given path.", help="Copy the PDF file to the given path.",
), ),
] = None, ] = None,
markdown_path: Annotated[ markdown_path: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--markdown-path",
"-md",
help="Copy the Markdown file to the given path.", help="Copy the Markdown file to the given path.",
), ),
] = None, ] = None,
html_path: Annotated[ html_path: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--html-path",
"-html",
help="Copy the HTML file to the given path.", help="Copy the HTML file to the given path.",
), ),
] = None, ] = None,
png_path: Annotated[ png_path: Annotated[
Optional[str], Optional[str],
typer.Option( typer.Option(
"--png-path",
"-png",
help="Copy the PNG file to the given path.", help="Copy the PNG file to the given path.",
), ),
] = None, ] = None,
@ -582,6 +597,7 @@ def cli_command_render(
bool, bool,
typer.Option( typer.Option(
"--dont-generate-markdown", "--dont-generate-markdown",
"-nomd",
help="Don't generate the Markdown and HTML file.", help="Don't generate the Markdown and HTML file.",
), ),
] = False, ] = False,
@ -589,6 +605,7 @@ def cli_command_render(
bool, bool,
typer.Option( typer.Option(
"--dont-generate-html", "--dont-generate-html",
"-nohtml",
help="Don't generate the HTML file.", help="Don't generate the HTML file.",
), ),
] = False, ] = False,
@ -596,6 +613,7 @@ def cli_command_render(
bool, bool,
typer.Option( typer.Option(
"--dont-generate-png", "--dont-generate-png",
"-nopng",
help="Don't generate the PNG file.", help="Don't generate the PNG file.",
), ),
] = False, ] = False,
@ -711,8 +729,8 @@ def cli_command_render(
@app.command( @app.command(
name="new", name="new",
help=( help=(
"Generate a YAML input file to get started. Example: [bold green]rendercv new" "Generate a YAML input file to get started. Example: [yellow]rendercv new"
' "John Doe"[/bold green]' ' "John Doe"[/yellow]. Details: [cyan]rendercv new --help[/cyan]'
), ),
) )
def cli_command_new( def cli_command_new(
@ -783,8 +801,9 @@ def cli_command_new(
@app.command( @app.command(
name="create-theme", name="create-theme",
help=( help=(
"Create a custom theme folder based on an existing theme. Example: [bold" "Create a custom theme folder based on an existing theme. Example:"
" green]rendercv create-theme --based-on classic customtheme[/bold green]" " [yellow]rendercv create-theme customtheme[/yellow]. Details: [cyan]rendercv"
" create-theme --help[/cyan]"
), ),
) )
def cli_command_create_theme( def cli_command_create_theme(
@ -844,7 +863,7 @@ def cli_command_create_theme(
@app.callback() @app.callback()
def main( def main(
version_requested: Annotated[ version_requested: Annotated[
Optional[bool], typer.Option("--version", help="Show the version.") Optional[bool], typer.Option("--version", "-v", help="Show the version.")
] = None, ] = None,
): ):
if version_requested: if version_requested: