1#![allow(clippy::all, clippy::pedantic, clippy::disallowed_methods)]
10#![allow(
11 unreachable_code,
12 unused_variables,
13 unused_imports,
14 dead_code,
15 unused_assignments
16)]
17
18use clap::{Parser, Subcommand};
19use std::path::{Path, PathBuf};
20
21#[macro_use]
23#[allow(unused_macros, clippy::duplicated_attributes)]
24mod generated_contracts;
25
26mod commands;
27pub mod error;
28mod output;
29pub mod pipe;
30
31pub use error::CliError;
32
33pub mod qa_types {
35 pub use crate::commands::qa::{GateResult, QaReport, SystemInfo};
36}
37
38pub mod model_pull {
40 pub use crate::commands::pull::{list, run};
41}
42
43#[cfg(feature = "inference")]
44pub mod federation;
45
46use commands::{
48 bench, canary, canary::CanaryCommands, cbtop, chat, compare_hf, compile, convert, data, debug,
49 diagnose, diff, distill, eval, explain, export, flow, hex, import, inspect, lint, mcp, merge,
50 oracle, pipeline, probar, profile, prune, publish, pull, qa, qualify, quantize, rosetta,
51 rosetta::RosettaCommands, run, serve, showcase, tensors, tokenize, trace, tree, tui, validate,
52 validate_manifest,
53};
54#[cfg(feature = "training")]
55use commands::{finetune, gpu, train, tune};
56
57#[derive(Parser, Debug)]
62#[command(name = "apr")]
63#[command(author, version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("APR_GIT_SHA"), ")"), about, long_about = None)]
64#[command(propagate_version = true)]
65pub struct Cli {
66 #[command(subcommand)]
67 pub command: Box<Commands>,
68
69 #[arg(long, global = true)]
71 pub json: bool,
72
73 #[arg(short, long, global = true)]
75 pub verbose: bool,
76
77 #[arg(short, long, global = true)]
79 pub quiet: bool,
80
81 #[arg(long, global = true)]
83 pub offline: bool,
84
85 #[arg(long, global = true)]
87 pub skip_contract: bool,
88}
89
90include!("commands_enum.rs");
91include!("model_ops_commands.rs");
92include!("extended_commands.rs");
93include!("tool_commands.rs");
94include!("data_commands.rs");
95#[cfg(feature = "training")]
96include!("train_commands.rs");
97include!("serve_commands.rs");
98include!("tokenize_commands.rs");
99include!("pipeline_commands.rs");
100include!("validate.rs");
101include!("dispatch_run.rs");
102include!("dispatch.rs");
103include!("dispatch_analysis.rs");
104include!("lib_07.rs");
105
106pub fn cli_main() -> std::process::ExitCode {
112 #[cfg(unix)]
114 #[allow(unsafe_code)]
115 unsafe {
116 libc::signal(libc::SIGPIPE, libc::SIG_DFL);
117 }
118
119 #[cfg(target_arch = "aarch64")]
121 #[allow(unsafe_code)]
122 unsafe {
123 let fpcr: u64;
124 core::arch::asm!("mrs {}, fpcr", out(reg) fpcr);
125 if fpcr & (1 << 19) != 0 {
126 let new_fpcr = fpcr & !(1 << 19);
127 core::arch::asm!("msr fpcr, {}", in(reg) new_fpcr);
128 }
129 }
130
131 let no_color = std::env::var("NO_COLOR").is_ok();
133 let is_tty = std::io::IsTerminal::is_terminal(&std::io::stdout());
134 if no_color || !is_tty {
135 colored::control::set_override(false);
136 }
137
138 let cli = Cli::parse();
139 match execute_command(&cli) {
140 Ok(()) => std::process::ExitCode::SUCCESS,
141 Err(e) => {
142 eprintln!("error: {e}");
143 e.exit_code()
144 }
145 }
146}