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, 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};
53#[cfg(feature = "training")]
54use commands::{finetune, gpu, train, tune};
55
56#[derive(Parser, Debug)]
61#[command(name = "apr")]
62#[command(author, version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("APR_GIT_SHA"), ")"), about, long_about = None)]
63#[command(propagate_version = true)]
64pub struct Cli {
65 #[command(subcommand)]
66 pub command: Box<Commands>,
67
68 #[arg(long, global = true)]
70 pub json: bool,
71
72 #[arg(short, long, global = true)]
74 pub verbose: bool,
75
76 #[arg(short, long, global = true)]
78 pub quiet: bool,
79
80 #[arg(long, global = true)]
82 pub offline: bool,
83
84 #[arg(long, global = true)]
86 pub skip_contract: bool,
87}
88
89include!("commands_enum.rs");
90include!("model_ops_commands.rs");
91include!("extended_commands.rs");
92include!("tool_commands.rs");
93include!("data_commands.rs");
94#[cfg(feature = "training")]
95include!("train_commands.rs");
96include!("serve_commands.rs");
97include!("tokenize_commands.rs");
98include!("pipeline_commands.rs");
99include!("validate.rs");
100include!("dispatch_run.rs");
101include!("dispatch.rs");
102include!("dispatch_analysis.rs");
103include!("lib_07.rs");
104
105pub fn cli_main() -> std::process::ExitCode {
111 #[cfg(unix)]
113 #[allow(unsafe_code)]
114 unsafe {
115 libc::signal(libc::SIGPIPE, libc::SIG_DFL);
116 }
117
118 #[cfg(target_arch = "aarch64")]
120 #[allow(unsafe_code)]
121 unsafe {
122 let fpcr: u64;
123 core::arch::asm!("mrs {}, fpcr", out(reg) fpcr);
124 if fpcr & (1 << 19) != 0 {
125 let new_fpcr = fpcr & !(1 << 19);
126 core::arch::asm!("msr fpcr, {}", in(reg) new_fpcr);
127 }
128 }
129
130 let no_color = std::env::var("NO_COLOR").is_ok();
132 let is_tty = std::io::IsTerminal::is_terminal(&std::io::stdout());
133 if no_color || !is_tty {
134 colored::control::set_override(false);
135 }
136
137 let cli = Cli::parse();
138 match execute_command(&cli) {
139 Ok(()) => std::process::ExitCode::SUCCESS,
140 Err(e) => {
141 eprintln!("error: {e}");
142 e.exit_code()
143 }
144 }
145}