use camel_cli::commands;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "camel",
version,
about = "Command-line interface for Apache Camel in Rust"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Run {
#[arg(long, value_name = "GLOB")]
routes: Option<String>,
#[arg(long, value_name = "FILE", default_value = "Camel.toml")]
config: String,
#[arg(long, overrides_with = "no_watch")]
watch: bool,
#[arg(long, overrides_with = "watch")]
no_watch: bool,
#[arg(long)]
otel: bool,
#[arg(long, value_name = "URL")]
otel_endpoint: Option<String>,
#[arg(long, value_name = "NAME")]
service_name: Option<String>,
#[arg(long, value_name = "PORT")]
health_port: Option<u16>,
},
Journal {
#[command(subcommand)]
action: JournalAction,
},
New(commands::new::NewArgs),
Plugin {
#[command(subcommand)]
action: commands::plugin::PluginAction,
},
}
#[derive(Subcommand)]
enum JournalAction {
Inspect(commands::journal::JournalInspectArgs),
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
match cli.command {
Commands::Run {
routes,
config,
watch,
no_watch,
otel,
otel_endpoint,
service_name,
health_port,
} => {
let cli_watch = if watch {
Some(true)
} else if no_watch {
Some(false)
} else {
None
};
if let Err(e) = commands::run::run(
routes,
config,
cli_watch,
otel,
otel_endpoint,
service_name,
health_port,
)
.await
{
commands::errors::report_cli_failure_and_exit("run", &e);
}
}
Commands::Journal { action } => match action {
JournalAction::Inspect(args) => {
commands::journal::run_inspect(args).await;
}
},
Commands::New(args) => {
commands::new::run_new(args);
}
Commands::Plugin { action } => {
commands::plugin::run_plugin(action);
}
}
}