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

View File

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

View File

@@ -5,7 +5,7 @@ from pathlib import Path
import pytest 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 primaite.utils.cli.primaite_config_utils import get_primaite_config_dict
from tests.integration_tests.cli import cli from tests.integration_tests.cli import cli