extern crate anyhow;
extern crate cargo_metadata;
extern crate colored;
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::process;
mod discover;
mod powerset;
#[derive(Parser)]
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
enum CargoCli {
Features(FeaturesCli),
}
#[derive(clap::Args)]
#[command(author, version, about = "Power tools for working with Cargo features")]
#[command(propagate_version = true)]
struct FeaturesCli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Discover {
#[arg(short, long)]
all: bool,
#[arg(short, long)]
manifest_path: Option<std::path::PathBuf>,
},
Powerset {
#[arg(long)]
skip_empty: bool,
#[arg(short, long)]
features: Vec<String>,
#[arg(long)]
manifest_path: Option<std::path::PathBuf>,
#[arg(required = true, num_args = 1..)]
cargo_command: Vec<String>,
},
}
fn main() {
let CargoCli::Features(cli) = CargoCli::parse();
if let Err(e) = run(cli) {
eprintln!("Error: {:#}", e);
process::exit(1);
}
}
fn run(cli: FeaturesCli) -> Result<()> {
match cli.command {
Commands::Discover { all, manifest_path } => discover::run(!all, manifest_path),
Commands::Powerset {
skip_empty,
features,
manifest_path,
cargo_command,
} => powerset::run(skip_empty, features, manifest_path, cargo_command),
}
}