derive_show_asm/
derive_show_asm.rsuse bpaf::{construct, long, Bpaf, Parser, ShellComp};
use std::{convert::Infallible, path::PathBuf};
#[derive(Clone, Debug, Bpaf)]
#[bpaf(options("asm"))] #[allow(clippy::struct_excessive_bools)]
pub struct Options {
#[bpaf(external(parse_manifest_path))]
pub manifest_path: PathBuf,
#[bpaf(argument("DIR"))]
pub target_dir: Option<PathBuf>,
#[bpaf(long, short, argument("SPEC"))]
pub package: Option<String>,
#[bpaf(external, optional)]
pub focus: Option<Focus>,
pub dry: bool,
pub frozen: bool,
pub locked: bool,
pub offline: bool,
#[bpaf(external)]
pub format: Format,
#[bpaf(external, fallback(Syntax::Intel))]
pub syntax: Syntax,
#[bpaf(external)]
pub selected_function: SelectedFunction,
}
#[derive(Debug, Clone, Bpaf)]
pub struct SelectedFunction {
#[bpaf(positional("FUNCTION"))]
pub function: Option<String>,
#[bpaf(positional("INDEX"), fallback(0))]
pub nth: usize,
}
fn parse_manifest_path() -> impl Parser<PathBuf> {
long("manifest-path")
.help("Path to Cargo.toml")
.argument::<PathBuf>("PATH")
.complete_shell(ShellComp::File {
mask: Some("*.toml"),
})
.parse(|p| {
if p.is_absolute() {
Ok(p)
} else {
std::env::current_dir()
.map(|d| d.join(p))
.and_then(|full_path| full_path.canonicalize())
}
})
.fallback_with(|| std::env::current_dir().map(|x| x.join("Cargo.toml")))
}
#[derive(Debug, Clone, Bpaf)]
pub struct Format {
pub rust: bool,
#[bpaf(external(color_detection))]
pub color: bool,
pub full_name: bool,
}
#[derive(Debug, Clone, Bpaf)]
pub enum Syntax {
Intel,
Att,
}
fn color_detection() -> impl Parser<bool> {
let yes = long("color")
.help("Enable color highlighting")
.req_flag(true);
let no = long("no-color")
.help("Disable color highlighting")
.req_flag(false);
construct!([yes, no]).fallback_with::<_, Infallible>(|| {
Ok(true)
})
}
fn comp_examples(prefix: &String) -> Vec<(String, Option<String>)> {
let examples = ["derive_show_asm", "coreutils", "comonad"];
examples
.iter()
.filter_map(|e| {
if e.starts_with(prefix) {
Some((e.to_string(), None))
} else {
None
}
})
.collect()
}
#[derive(Debug, Clone, Bpaf)]
pub enum Focus {
Lib,
Test(
#[bpaf(long("test"), argument("TEST"))]
String,
),
Bench(
#[bpaf(long("bench"), argument("BENCH"))]
String,
),
Example(
#[bpaf(long("example"), argument("EXAMPLE"), complete(comp_examples))]
String,
),
Bin(
#[bpaf(long("bin"), argument("BIN"))]
String,
),
}
fn main() {
println!("{:#?}", options().run());
}