//! See . //! //! This binary defines various auxiliary build commands, which are not //! expressible with just `cargo`. //! //! This binary is integrated into the `cargo` command line by using an alias in //! `.cargo/config`. use std::path::PathBuf; use anyhow::Result; use clap::{Parser, Subcommand}; use xtask::{dist, release}; fn main() -> Result<()> { let cli = Cli::parse(); std::env::set_current_dir(cli.directory)?; match cli.command { Commands::Dist { tag } => { let targz = dist::generate_tar_gz(&cli.profile, tag.as_deref())?; println!("{}", targz.display()); } Commands::OutDir => { let out_dir = dist::find_out_dir(&cli.profile)?; println!("{}", out_dir.display()); } Commands::Release(release) => release.run()?, }; Ok(()) } #[derive(Debug, Clone, Parser)] #[command(author, version, about)] struct Cli { #[command(subcommand)] command: Commands, /// Cargo profile to use. #[arg(short, long, default_value = "release")] profile: String, /// Change to DIRECTORY before doing anything #[arg(short='C', long, default_value_os_t = get_package_dir())] directory: PathBuf, } #[derive(Debug, Clone, Subcommand)] enum Commands { /// Print the default value of OUT_DIR used by cargo when building the package. OutDir, /// Generate distributable package and print it's path Dist { /// Verify the package version matches the provided tag. #[arg(short, long)] tag: Option, }, Release(release::Release), } fn get_package_dir() -> PathBuf { std::path::Path::new(&env!("CARGO_MANIFEST_DIR")) .parent() .unwrap() .to_path_buf() }