-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.rs
More file actions
77 lines (72 loc) · 2.63 KB
/
Copy pathmain.rs
File metadata and controls
77 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
mod cli;
mod commands;
mod dispatch;
#[cfg(feature = "mcp")]
mod mcp;
mod output;
mod problem_name;
mod util;
use clap::{CommandFactory, Parser};
use cli::{Cli, Commands};
use output::OutputConfig;
fn main() -> anyhow::Result<()> {
let cli = match Cli::try_parse() {
Ok(cli) => cli,
Err(e) => {
// Let --help and --version print normally
if e.kind() == clap::error::ErrorKind::DisplayHelp
|| e.kind() == clap::error::ErrorKind::DisplayVersion
{
e.exit();
}
let msg = e.to_string();
eprint!("{e}");
// Show the subcommand's after_help (defined once in cli.rs)
cli::print_subcommand_help_hint(&msg);
std::process::exit(e.exit_code());
}
};
// Data-producing commands auto-output JSON when piped
let auto_json = matches!(
cli.command,
Commands::Reduce(_) | Commands::Solve(_) | Commands::Evaluate(_) | Commands::Inspect(_)
);
let out = OutputConfig {
output: cli.output,
quiet: cli.quiet,
json: cli.json,
auto_json,
};
match cli.command {
Commands::List => commands::graph::list(&out),
Commands::Show { problem } => commands::graph::show(&problem, &out),
Commands::To { problem, hops } => commands::graph::neighbors(&problem, hops, "in", &out),
Commands::From { problem, hops } => commands::graph::neighbors(&problem, hops, "out", &out),
Commands::Path {
source,
target,
cost,
all,
} => commands::graph::path(&source, &target, &cost, all, &out),
Commands::ExportGraph => commands::graph::export(&out),
Commands::Inspect(args) => commands::inspect::inspect(&args.input, &out),
Commands::Create(args) => commands::create::create(&args, &out),
Commands::Solve(args) => {
commands::solve::solve(&args.input, &args.solver, args.timeout, &out)
}
Commands::Reduce(args) => {
commands::reduce::reduce(&args.input, args.to.as_deref(), args.via.as_deref(), &out)
}
Commands::Evaluate(args) => commands::evaluate::evaluate(&args.input, &args.config, &out),
#[cfg(feature = "mcp")]
Commands::Mcp => mcp::run(),
Commands::Completions { shell } => {
let shell = shell
.or_else(clap_complete::Shell::from_env)
.unwrap_or(clap_complete::Shell::Bash);
let mut cmd = Cli::command();
clap_complete::generate(shell, &mut cmd, "pred", &mut std::io::stdout());
Ok(())
}
}
}