Implement the shared automation CLI.

This commit is contained in:
2026-07-19 14:25:15 +02:00
parent a2abb901cd
commit fdfae200a0
33 changed files with 2411 additions and 58 deletions

View File

@@ -1,3 +1,52 @@
fn main() {
println!("bds-cli: headless automation surface (not yet implemented)");
use std::io::Read as _;
use std::process::ExitCode;
use clap::Parser;
fn main() -> ExitCode {
let cli = match bds_cli::Cli::try_parse() {
Ok(cli) => cli,
Err(error) => {
let success = matches!(
error.kind(),
clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion
);
let _ = error.print();
return if success {
ExitCode::SUCCESS
} else {
ExitCode::from(1)
};
}
};
let json = cli.json;
let needs_stdin = match &cli.command {
bds_cli::Command::Post(args) => args.stdin,
bds_cli::Command::Gallery(args) => args.post.stdin,
_ => false,
};
let mut context = bds_cli::RunContext::system();
if needs_stdin && let Err(error) = std::io::stdin().read_to_string(&mut context.stdin) {
eprintln!("Error: could not read stdin: {error}");
return ExitCode::from(1);
}
match bds_cli::run(cli, context) {
Ok(output) => {
println!("{output}");
ExitCode::SUCCESS
}
Err(error) => {
if json {
eprintln!(
"{}",
serde_json::json!({"ok": false, "error": format!("{error:#}")})
);
} else {
eprintln!("Error: {error:#}");
}
ExitCode::from(1)
}
}
}