mod commands;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use std::process::ExitCode;
#[derive(Parser)]
#[command(
name = "gpx",
about = "A command-line tool for working with GPX files",
version
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Validate {
input_file: PathBuf,
#[arg(long)]
strict: bool,
#[arg(long)]
json: bool,
},
Info {
input_file: PathBuf,
#[arg(long)]
json: bool,
#[arg(long)]
strict: bool,
},
Edit {
input_file: PathBuf,
#[arg(short, long)]
output_file: PathBuf,
#[arg(long)]
strict: bool,
#[command(flatten)]
options: Box<commands::EditOptions>,
},
Merge {
input_files: Vec<PathBuf>,
#[arg(short, long)]
output_file: PathBuf,
#[arg(long)]
strict: bool,
},
Convert {
input_file: PathBuf,
#[arg(short, long)]
output_file: PathBuf,
#[arg(long)]
strict: bool,
},
}
pub fn run() -> ExitCode {
let cli = Cli::parse();
let result = match cli.command {
Command::Validate {
input_file,
strict,
json,
} => commands::validate(&input_file, strict, json),
Command::Info {
input_file,
json,
strict,
} => commands::info(&input_file, json, strict),
Command::Edit {
input_file,
output_file,
strict,
options,
} => commands::edit(&input_file, &output_file, strict, *options),
Command::Merge {
input_files,
output_file,
strict,
} => commands::merge(&input_files, &output_file, strict),
Command::Convert {
input_file,
output_file,
strict,
} => commands::convert(&input_file, &output_file, strict),
};
match result {
Ok(code) => ExitCode::from(code),
Err(err) => {
eprintln!("Error: {err}");
ExitCode::from(1)
}
}
}