Coverage for src/somesy/cli/init.py: 24%
50 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
1"""Set config files for somesy."""
2import logging
3from pathlib import Path
5import typer
7from somesy.commands import init_config
8from somesy.core.core import discover_input
9from somesy.core.log import SomesyLogLevel, set_log_level
11from .util import wrap_exceptions
13logger = logging.getLogger("somesy")
14app = typer.Typer()
17@app.command()
18@wrap_exceptions
19def config():
20 """Set CLI configs for somesy."""
21 # check if input file exists, if not, try to find it from default list
22 input_file_default = discover_input()
24 # prompt for inputs
25 input_file = typer.prompt("Input file path", default=input_file_default)
26 options = dict(input_file=Path(input_file))
28 # ----
30 options["no_sync_cff"] = not typer.confirm(
31 "Do you want to sync to a CFF file?", default=True
32 )
33 if cff_file := typer.prompt("CFF file path", default="CITATION.cff"):
34 options["cff_file"] = cff_file
36 options["no_sync_codemeta"] = not typer.confirm(
37 "Do you want to sync to a codemeta.json file?", default=True
38 )
39 if codemeta_file := typer.prompt(
40 "codemeta.json file path", default="codemeta.json"
41 ):
42 options["codemeta_file"] = codemeta_file
44 options["no_sync_pyproject"] = not typer.confirm(
45 "Do you want to sync to a pyproject.toml file?", default=True
46 )
47 if pyproject_file := typer.prompt(
48 "pyproject.toml file path", default="pyproject.toml"
49 ):
50 options["pyproject_file"] = pyproject_file
52 options["sync_package_json"] = typer.confirm(
53 "Do you want to sync to a package.json file?", default=False
54 )
55 if package_json_file := typer.prompt(
56 "package.json file path", default="package.json"
57 ):
58 options["package_json_file"] = package_json_file
60 options["no_sync_julia"] = not typer.confirm(
61 "Do you want to sync to a Project.toml(Julia) file?", default=True
62 )
63 if julia_file := typer.prompt(
64 "Project.toml (Julia) file path", default="Project.toml"
65 ):
66 options["julia_file"] = julia_file
68 options["no_sync_fortran"] = not typer.confirm(
69 "Do you want to sync to a fpm.toml(fortran) file?", default=True
70 )
71 fortran_file = typer.prompt("fpm.toml(fortran) file path", default="fpm.toml")
72 if fortran_file is not None or fortran_file != "":
73 options["fortran_file"] = fortran_file
75 options["no_sync_pom_xml"] = not typer.confirm(
76 "Do you want to sync to a pom.xml file?", default=True
77 )
78 if pom_xml_file := typer.prompt("pom.xml file path", default="pom.xml"):
79 options["pom_xml_file"] = pom_xml_file
81 options["no_sync_mkdocs"] = not typer.confirm(
82 "Do you want to sync to a mkdocs.yml file?", default=True
83 )
84 if mkdocs_file := typer.prompt("mkdocs.yml file path", default="mkdocs.yml"):
85 options["mkdocs_file"] = mkdocs_file
87 options["no_sync_rust"] = not typer.confirm(
88 "Do you want to sync to a Cargo.toml file?", default=True
89 )
90 if rust_file := typer.prompt("Cargo.toml file path", default="Cargo.toml"):
91 options["rust_file"] = rust_file
93 # ----
95 options["show_info"] = typer.confirm(
96 "Do you want to show info about the sync process?"
97 )
98 options["verbose"] = typer.confirm("Do you want to show verbose logs?")
99 options["debug"] = typer.confirm("Do you want to show debug logs?")
101 set_log_level(
102 SomesyLogLevel.from_flags(
103 debug=options["debug"],
104 verbose=options["verbose"],
105 info=options["show_info"],
106 )
107 )
109 logger.debug(f"CLI options entered: {options}")
111 init_config(input_file, options)
112 logger.info(
113 f"[bold green]Input file is updated/created at {input_file}[/bold green]"
114 )