This repository has been archived on 2023-01-14. You can view files and clone it, but cannot push or open issues or pull requests.
toolkit/crates/sourcegraph/src/search.rs

33 lines
1.1 KiB
Rust

pub struct Search;
impl util::Cmd for Search {
fn cmd() -> eyre::Result<clap::Command> {
Ok(clap::Command::new("search")
.allow_external_subcommands(true)
.allow_missing_positional(true))
}
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
match args.subcommand() {
Some((external, args)) => {
let raw = args
.get_many::<std::ffi::OsString>("")
.ok_or(eyre::anyhow!("please pass some args to search"))?
.map(|s| s.as_os_str())
.map(|s| s.to_string_lossy().to_string())
.collect::<Vec<String>>();
let cmd = format!("src search {external} {}", raw.join(" "));
println!("{cmd}");
let mut cmd_args = vec!["src", "search", external];
cmd_args.append(&mut raw.iter().map(|s| &**s).collect());
util::shell::run(cmd_args.as_slice(), None)?;
}
_ => todo!(),
}
Ok(())
}
}