#![forbid(unsafe_code)]
use clap::{CommandFactory, Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "oxiproto-cli",
about = "Compile .proto files to plain Rust structs"
)]
struct Cli {
#[arg(
long,
short = 'q',
global = true,
help = "Suppress all non-error output"
)]
quiet: bool,
#[arg(long, short = 'v', global = true, help = "Print verbose progress")]
verbose: bool,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Gen(gen::GenArgs),
Describe(describe::DescribeArgs),
Encode(convert::ConvertArgs),
Decode(convert::ConvertArgs),
Breaking(breaking::BreakingArgs),
Doc(doc::DocArgs),
Format(format::FormatArgs),
Lint(lint::LintArgs),
Completions {
#[arg(value_enum)]
shell: clap_complete::Shell,
},
Man {
#[arg(long, short, default_value = ".")]
output: std::path::PathBuf,
},
}
fn main() {
let cli = Cli::parse();
let verbosity = util::Verbosity {
quiet: cli.quiet,
verbose: cli.verbose,
};
let result = match cli.command {
Command::Gen(args) => gen::run(args, verbosity),
Command::Describe(args) => describe::run(args, verbosity),
Command::Encode(args) => convert::run_encode(args, verbosity),
Command::Decode(args) => convert::run_decode(args, verbosity),
Command::Breaking(args) => breaking::run(args, verbosity),
Command::Doc(args) => doc::run(args, verbosity),
Command::Format(args) => format::run(args, verbosity),
Command::Lint(args) => lint::run(args, verbosity),
Command::Completions { shell } => {
let mut cmd = Cli::command();
let bin_name = cmd.get_name().to_owned();
clap_complete::generate(shell, &mut cmd, bin_name, &mut std::io::stdout());
Ok(())
}
Command::Man { output } => man::run(output, verbosity),
};
if let Err(e) = result {
verbosity.error(&e.to_string());
std::process::exit(1);
}
}
mod breaking;
mod convert;
mod describe;
mod doc;
mod format;
mod gen;
mod lint;
mod man;
mod util;