This commit is contained in:
Czar Echavez
2024-04-30 15:50:53 +01:00
parent 59990813f5
commit ab3d23785d
3 changed files with 55 additions and 64 deletions

View File

@@ -1,5 +1,3 @@
from typing import List
import click
import typer
from rich import print
@@ -73,44 +71,38 @@ def disable():
def config_callback(
ctx: typer.Context,
sys_log_level: Annotated[
LogLevel,
typer.Option(
"--sys-log-level",
"-level",
click_type=click.Choice(LogLevel._member_names_, case_sensitive=False),
help="The level of system logs to output.",
show_default=False
)
] = None,
output_sys_logs: Annotated[
bool,
typer.Option(
"--output-sys-logs/--no-sys-logs",
"-sys/-nsys",
help="Output system logs to file.",
show_default=False
)
] = None,
output_pcap_logs: Annotated[
bool,
typer.Option(
"--output-pcap-logs/--no-pcap-logs",
"-pcap/-npcap",
help="Output network packet capture logs to file.",
show_default=False
),
] = None,
output_to_terminal: Annotated[
bool,
typer.Option(
"--output-to-terminal/--no-terminal",
"-t/-nt",
help="Output system logs to terminal.",
show_default=False
)
] = None,
ctx: typer.Context,
sys_log_level: Annotated[
LogLevel,
typer.Option(
"--sys-log-level",
"-level",
click_type=click.Choice(LogLevel._member_names_, case_sensitive=False),
help="The level of system logs to output.",
show_default=False,
),
] = None,
output_sys_logs: Annotated[
bool,
typer.Option(
"--output-sys-logs/--no-sys-logs", "-sys/-nsys", help="Output system logs to file.", show_default=False
),
] = None,
output_pcap_logs: Annotated[
bool,
typer.Option(
"--output-pcap-logs/--no-pcap-logs",
"-pcap/-npcap",
help="Output network packet capture logs to file.",
show_default=False,
),
] = None,
output_to_terminal: Annotated[
bool,
typer.Option(
"--output-to-terminal/--no-terminal", "-t/-nt", help="Output system logs to terminal.", show_default=False
),
] = None,
):
"""Configure the development tools and environment."""
config_dict = get_primaite_config_dict()
@@ -122,7 +114,6 @@ def config_callback(
config_dict["developer_mode"]["sys_log_level"] = ctx.params.get("sys_log_level")
print(f"PrimAITE dev-mode config updated sys_log_level={ctx.params.get('sys_log_level')}")
if output_sys_logs is not None:
config_dict["developer_mode"]["output_sys_logs"] = output_sys_logs
print(f"PrimAITE dev-mode config updated {output_sys_logs=}")
@@ -150,22 +141,22 @@ dev.add_typer(config_typer)
@config_typer.command()
def path(
directory: Annotated[
str,
typer.Argument(
help="Directory where the system logs and PCAP logs will be output. By default, this will be where the"
"root of the PrimAITE repository is located.",
show_default=False,
),
] = None,
default: Annotated[
bool,
typer.Option(
"--default",
"-root",
help="Set PrimAITE to output system logs and pcap logs to the PrimAITE repository root.",
),
] = None,
directory: Annotated[
str,
typer.Argument(
help="Directory where the system logs and PCAP logs will be output. By default, this will be where the"
"root of the PrimAITE repository is located.",
show_default=False,
),
] = None,
default: Annotated[
bool,
typer.Option(
"--default",
"-root",
help="Set PrimAITE to output system logs and pcap logs to the PrimAITE repository root.",
),
] = None,
):
"""Set the output directory for the PrimAITE system and PCAP logs."""
config_dict = get_primaite_config_dict()
@@ -177,9 +168,11 @@ def path(
config_dict["developer_mode"]["output_dir"] = None
# update application config
update_primaite_config(config_dict)
print(f"PrimAITE dev-mode output_dir [medium_turquoise]"
f"{str(_PRIMAITE_ROOT.parent.parent / 'simulation_output')}"
f"[/medium_turquoise]")
print(
f"PrimAITE dev-mode output_dir [medium_turquoise]"
f"{str(_PRIMAITE_ROOT.parent.parent / 'simulation_output')}"
f"[/medium_turquoise]"
)
return
if directory:

View File

@@ -6,9 +6,7 @@ import yaml
from primaite import PRIMAITE_PATHS
def get_primaite_config_dict(
config_path: Optional[Path] = None
) -> Dict:
def get_primaite_config_dict(config_path: Optional[Path] = None) -> Dict:
"""
Returns a dict containing the PrimAITE application config.

View File

@@ -5,7 +5,7 @@ from pathlib import Path
import pytest
from primaite import PRIMAITE_PATHS, _PRIMAITE_ROOT
from primaite import _PRIMAITE_ROOT, PRIMAITE_PATHS
from primaite.utils.cli.primaite_config_utils import get_primaite_config_dict
from tests.integration_tests.cli import cli