Package portable grid agent operation (#134)
Some checks failed
CI / rust-skia (Rust only) (push) Successful in 2m48s
CI / required (push) Failing after 51s

This commit is contained in:
2026-08-18 12:27:07 +02:00
parent fe8d0119ef
commit 00707fd8df
14 changed files with 693 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ enum Operation {
RunOnce,
Tui,
TuiClient,
PrintPaths,
}
#[derive(Default)]
@@ -56,10 +57,14 @@ fn options() -> Result<Option<Options>, CliError> {
}
if argument == "--help" || argument == "-h" {
println!(
"metacrate-grid-agent [--config PATH] [--check-config | --run-once | --tui | --tui-client]\n\
Configuration precedence: defaults < JSON < secret files < environment."
"metacrate-grid-agent [--config PATH] [--check-config | --run-once | --tui | --tui-client | --print-paths]\n\
Configuration precedence: defaults < JSON < secret files < environment.\n\
With no --config, the platform default is used when it exists."
);
return Ok(None);
} else if argument == "--version" || argument == "-V" {
println!("metacrate-grid-agent {}", env!("CARGO_PKG_VERSION"));
return Ok(None);
}
if argument == "--check-config" {
set_operation(&mut result, Operation::CheckConfig)?;
@@ -69,6 +74,8 @@ fn options() -> Result<Option<Options>, CliError> {
set_operation(&mut result, Operation::Tui)?;
} else if argument == "--tui-client" {
set_operation(&mut result, Operation::TuiClient)?;
} else if argument == "--print-paths" {
set_operation(&mut result, Operation::PrintPaths)?;
} else if argument == "--config" {
let path = arguments
.next()
@@ -99,8 +106,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
let Some(options) = options()? else {
return Ok(());
};
let platform_paths = metacrate_grid_agent::PlatformPaths::discover();
if options.operation == Operation::PrintPaths {
println!("config={}", platform_paths.config_file.display());
println!("data={}", platform_paths.data_directory.display());
return Ok(());
}
let mut loader = ConfigLoader::new();
if let Some(path) = options.config {
let config_path = options.config.or_else(|| {
platform_paths
.config_file
.is_file()
.then_some(platform_paths.config_file)
});
if let Some(path) = config_path {
loader = loader.with_file(path);
}
let config = loader.load()?;