#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![warn(missing_docs)]
mod cli;
mod commands;
mod man;
mod output;
#[cfg(test)]
mod proptest_cases;
mod render;
use std::process::ExitCode;
use clap::{CommandFactory, Parser, error::ErrorKind};
use sokf_core::CacheMode;
use crate::cli::{Cli, Command, CompletionsArgs};
fn main() -> ExitCode {
agent_harness_adapter_core::cli::finish(run())
}
fn run() -> sokf_core::Result<u8> {
let cli = Cli::parse();
if cli.version {
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
return Ok(output::EXIT_OK);
}
let Some(command) = cli.command else {
Cli::command().print_help().ok();
return Ok(output::EXIT_OK);
};
if let Some(schema) = command.json_schema() {
if cli.repo_root.is_some() || cli.no_cache {
Cli::command()
.error(
ErrorKind::ArgumentConflict,
"the argument '--json-schema' cannot be used with one or more of the other specified arguments",
)
.exit();
}
return output::print_schema(schema);
}
let repo_root = cli.repo_root.as_deref();
let cache = if cli.no_cache {
CacheMode::Off
} else {
CacheMode::On
};
match command {
Command::Init(args) => commands::init(repo_root, args),
Command::Harness(args) => commands::harness(repo_root, cache, args),
Command::Pack(args) => commands::pack(repo_root, args),
Command::Validate(args) => commands::validate(repo_root, cache, args),
Command::Info(args) => commands::info(repo_root, cache, args),
Command::New(args) => commands::new(repo_root, cache, args),
Command::Graph(args) => commands::graph(repo_root, cache, args),
Command::Locate(args) => commands::locate(repo_root, cache, args),
Command::Completions(args) => run_completions(args),
Command::Man => run_man(),
}
}
fn run_completions(args: CompletionsArgs) -> sokf_core::Result<u8> {
let mut cmd = Cli::command();
let name = cmd.get_name().to_string();
let mut buf = Vec::new();
clap_complete::generate(args.shell, &mut cmd, name, &mut buf);
output::write_stdout(&buf)?;
Ok(output::EXIT_OK)
}
fn run_man() -> sokf_core::Result<u8> {
let buf = man::render().map_err(output::stdout_err)?;
output::write_stdout(&buf)?;
Ok(output::EXIT_OK)
}