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/github/src/lib.rs
2022-12-18 01:41:12 +01:00

49 lines
1.5 KiB
Rust

mod auth;
mod fuzzy_clone;
mod gh;
pub struct GitHub;
impl GitHub {
fn run(external: &str, args: &clap::ArgMatches) -> eyre::Result<()> {
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!["gh", external];
cmd_args.append(&mut raw.iter().map(|s| &**s).collect());
util::shell::run(cmd_args.as_slice(), None)?;
Ok(())
}
}
impl util::Cmd for GitHub {
fn cmd() -> eyre::Result<clap::Command> {
Ok(clap::Command::new("github")
.subcommands(&[
auth::Auth::cmd()?,
gh::Gh::cmd()?,
fuzzy_clone::FuzzyClone::cmd()?,
])
.allow_external_subcommands(true))
}
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
match args.subcommand() {
Some(("auth", subm)) => auth::Auth::exec(subm),
Some(("fuzzy-clone", subm)) => fuzzy_clone::FuzzyClone::exec(subm),
Some(("fc", subm)) => fuzzy_clone::FuzzyClone::exec(subm),
Some(("gh", subm)) => gh::Gh::exec(subm),
Some((external, args)) => Self::run(external, args),
_ => Err(eyre::anyhow!("missing argument")),
}
}
}