Skip to content

init_config

CLI command to initialize somesy configuration file.

init_config

init_config(input_path: Path, options: dict) -> None

Initialize somesy configuration file.

Parameters:

Name Type Description Default
input_path Path

Path to somesy file (will be created/overwritten).

required
options dict

CLI options.

required
Source code in src/somesy/commands/init_config.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def init_config(input_path: Path, options: dict) -> None:
    """Initialize somesy configuration file.

    Args:
        input_path (Path): Path to somesy file (will be created/overwritten).
        options (dict): CLI options.
    """
    logger.info(f"Updating input file ({input_path}) with CLI configurations...")

    content = get_input_content(input_path, no_unwrap=True)

    is_somesy = SomesyInput.is_somesy_file_path(input_path)
    input_file_type = "somesy" if is_somesy else "pyproject"
    msg = f"Found input file with {input_file_type} format."
    logger.verbose(msg)

    logger.debug(f"Input file content: {options}")

    if "input_file" in options:
        del options["input_file"]
    if is_somesy:
        content["config"] = options
    else:
        if "tool" not in content:
            content["tool"] = {}
        if "somesy" not in content["tool"]:
            content["tool"]["somesy"] = {}
        content["tool"]["somesy"]["config"] = options

    with open(input_path, "w") as f:
        tomlkit.dump(content, f)

    logger.info(f"Input file ({input_path}) updated.")
    logger.debug(f"Input file content: {content}")