with sourcegraph as well

This commit is contained in:
2022-12-17 22:56:07 +01:00
parent 6dc747f8b0
commit 51b54f83b6
8 changed files with 104 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
[package]
name = "sourcegraph"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
util = { path = "../util" }
eyre.workspace = true
clap.workspace = true
dirs.workspace = true

View File

@@ -0,0 +1,13 @@
pub struct Auth;
impl util::Cmd for Auth {
fn cmd() -> eyre::Result<clap::Command> {
Ok(clap::Command::new("auth"))
}
fn exec(_: &clap::ArgMatches) -> eyre::Result<()> {
util::shell::run(&["src", "login"])?;
Ok(())
}
}

View File

@@ -0,0 +1,25 @@
mod auth;
mod search;
pub struct Sourcegraph;
impl Sourcegraph {
fn run() -> eyre::Result<()> {
Ok(())
}
}
impl util::Cmd for Sourcegraph {
fn cmd() -> eyre::Result<clap::Command> {
Ok(clap::Command::new("sourcegraph")
.subcommands(&[auth::Auth::cmd()?, search::Search::cmd()?]))
}
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
match args.subcommand() {
Some(("auth", subm)) => auth::Auth::exec(subm),
Some(("search", subm)) => search::Search::exec(subm),
_ => Self::run(),
}
}
}

View File

@@ -0,0 +1,34 @@
use std::{borrow::Borrow, ffi::OsString};
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 mut raw = args
.get_many::<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())?;
}
_ => todo!(),
}
Ok(())
}
}