fix: added some default values to the file.

This commit is contained in:
Akib
2024-09-01 15:38:24 +00:00
parent 419706aa48
commit 3a013a7b3f
3 changed files with 44 additions and 12 deletions

View File

@@ -57,7 +57,7 @@ def cli_command_render(
"-o",
help="Name of the output folder.",
),
] = None,
] = "rendercv_output",
latex_path: Annotated[
Optional[str],
typer.Option(
@@ -105,7 +105,7 @@ def cli_command_render(
"-nomd",
help="Don't generate the Markdown and HTML file.",
),
] = None,
] = False,
dont_generate_html: Annotated[
bool,
typer.Option(
@@ -113,7 +113,7 @@ def cli_command_render(
"-nohtml",
help="Don't generate the HTML file.",
),
] = None,
] = False,
dont_generate_png: Annotated[
bool,
typer.Option(
@@ -121,7 +121,7 @@ def cli_command_render(
"-nopng",
help="Don't generate the PNG file.",
),
] = None,
] = False,
# This is a dummy argument for the help message for
# extra_data_model_override_argumets:
_: Annotated[
@@ -144,6 +144,7 @@ def cli_command_render(
# dictionary for command line arguments:
cli_args = {
"use_local_latex_command": use_local_latex_command,
"output_folder_name": output_folder_name,
"latex_path": latex_path,
"pdf_path": pdf_path,
@@ -154,6 +155,20 @@ def cli_command_render(
"no_html": dont_generate_html,
"no_png": dont_generate_png,
}
# Create the default values for the cli_args:
cli_args_default = {
"use_local_latex_command": None,
"output_folder_name": "rendercv_output",
"latex_path": None,
"pdf_path": None,
"markdown_path": None,
"html_path": None,
"png_path": None,
"no_markdown": False,
"no_html": False,
"no_png": False,
}
# change the current working directory to the input file's directory (because
# the template overrides are looked up in the current working directory):
@@ -182,9 +197,7 @@ def cli_command_render(
)
# update the data of the rendercv settings:
render_cv_settings = data_as_a_dict.get("rendercv_settings", dict())
render_cv_settings = utilities.build_rendercv_settings(
render_cv_settings, cli_args
)
render_cv_settings = utilities.build_rendercv_settings(render_cv_settings, cli_args, cli_args_default)
# update the data model with the rendercv settings:
data_as_a_dict["rendercv_settings"] = render_cv_settings
@@ -193,9 +206,7 @@ def cli_command_render(
data_as_a_dict
)
output_directory = (
pathlib.Path.cwd() / data_model.rendercv_settings.output_folder_name
)
output_directory = pathlib.Path(data_model.rendercv_settings.output_folder_name)
progress.finish_the_current_step()

View File

@@ -265,6 +265,7 @@ def parse_render_command_override_arguments(
def build_rendercv_settings(
dictionary: dict,
command_line_arguments: dict[str, str],
command_line_arguments_default_values: dict[str, str],
) -> dict[str, str]:
"""Build the RenderCV settings dictionary by combining the dictionary and the command line arguments.
@@ -278,6 +279,16 @@ def build_rendercv_settings(
"""
# Combine the dictionary and the command line arguments if the values are not None:
for key, value in command_line_arguments.items():
if value is not None:
dictionary = set_or_update_a_value(dictionary, key, value) # type: ignore
# check if the key is present in the both command line arguments and the default values:
if key in command_line_arguments_default_values:
default_value = command_line_arguments_default_values[key]
if value != default_value:
dictionary = set_or_update_a_value(dictionary, key, value)
else:
# The key is not present in the default values, set the value:
# throw an error reporting this
raise ValueError(
f"The key ({key}) is not present in the default values of the command"
" line arguments!"
)
return dictionary

View File

@@ -26,6 +26,16 @@ class RenderCVSettings(pydantic.BaseModel):
' value is "rendercv_output".'
),
)
use_local_latex_command: Optional[str] = pydantic.Field(
default=None,
title="Local LaTeX Command",
description=(
"The command to compile the LaTeX file to a PDF file. The default value is"
' "pdflatex".'
),
)
pdf_path: Optional[str] = pydantic.Field(
default=None,