MeiliSearch/xtask/src/main.rs

46 lines
1.3 KiB
Rust
Raw Normal View History

2024-01-09 13:24:33 +01:00
use std::collections::HashSet;
use clap::Parser;
2024-02-26 21:29:20 +01:00
use xtask::bench::BenchDeriveArgs;
2024-01-09 13:24:33 +01:00
/// List features available in the workspace
#[derive(Parser, Debug)]
struct ListFeaturesDeriveArgs {
/// Feature to exclude from the list. Repeat the argument to exclude multiple features
#[arg(short, long)]
exclude_feature: Vec<String>,
}
/// Utilitary commands
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
#[command(name = "cargo xtask")]
#[command(bin_name = "cargo xtask")]
enum Command {
ListFeatures(ListFeaturesDeriveArgs),
2024-02-26 21:29:20 +01:00
Bench(BenchDeriveArgs),
2024-01-09 13:24:33 +01:00
}
2024-02-26 21:29:20 +01:00
fn main() -> anyhow::Result<()> {
2024-01-09 13:24:33 +01:00
let args = Command::parse();
match args {
Command::ListFeatures(args) => list_features(args),
2024-02-26 21:29:20 +01:00
Command::Bench(args) => xtask::bench::run(args)?,
2024-01-09 13:24:33 +01:00
}
2024-02-26 21:29:20 +01:00
Ok(())
2024-01-09 13:24:33 +01:00
}
fn list_features(args: ListFeaturesDeriveArgs) {
let exclude_features: HashSet<_> = args.exclude_feature.into_iter().collect();
let metadata = cargo_metadata::MetadataCommand::new().no_deps().exec().unwrap();
let features: Vec<String> = metadata
.packages
.iter()
.flat_map(|package| package.features.keys())
.filter(|feature| !exclude_features.contains(feature.as_str()))
.map(|s| s.to_owned())
.collect();
let features = features.join(" ");
println!("{features}")
}