2022-12-17 23:27:41 +01:00
|
|
|
mod auth;
|
2022-12-18 01:41:12 +01:00
|
|
|
mod fuzzy_clone;
|
2022-12-17 23:27:41 +01:00
|
|
|
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());
|
|
|
|
|
2022-12-18 01:41:12 +01:00
|
|
|
util::shell::run(cmd_args.as_slice(), None)?;
|
2022-12-17 23:27:41 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl util::Cmd for GitHub {
|
|
|
|
fn cmd() -> eyre::Result<clap::Command> {
|
|
|
|
Ok(clap::Command::new("github")
|
2022-12-18 01:41:12 +01:00
|
|
|
.subcommands(&[
|
|
|
|
auth::Auth::cmd()?,
|
|
|
|
gh::Gh::cmd()?,
|
|
|
|
fuzzy_clone::FuzzyClone::cmd()?,
|
|
|
|
])
|
2022-12-17 23:27:41 +01:00
|
|
|
.allow_external_subcommands(true))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
|
|
|
|
match args.subcommand() {
|
|
|
|
Some(("auth", subm)) => auth::Auth::exec(subm),
|
2022-12-18 01:41:12 +01:00
|
|
|
Some(("fuzzy-clone", subm)) => fuzzy_clone::FuzzyClone::exec(subm),
|
|
|
|
Some(("fc", subm)) => fuzzy_clone::FuzzyClone::exec(subm),
|
2022-12-17 23:27:41 +01:00
|
|
|
Some(("gh", subm)) => gh::Gh::exec(subm),
|
|
|
|
Some((external, args)) => Self::run(external, args),
|
|
|
|
_ => Err(eyre::anyhow!("missing argument")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|