with sourcegraph as well
This commit is contained in:
13
crates/sourcegraph/Cargo.toml
Normal file
13
crates/sourcegraph/Cargo.toml
Normal 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
|
13
crates/sourcegraph/src/auth.rs
Normal file
13
crates/sourcegraph/src/auth.rs
Normal 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(())
|
||||
}
|
||||
}
|
25
crates/sourcegraph/src/lib.rs
Normal file
25
crates/sourcegraph/src/lib.rs
Normal 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(),
|
||||
}
|
||||
}
|
||||
}
|
34
crates/sourcegraph/src/search.rs
Normal file
34
crates/sourcegraph/src/search.rs
Normal 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(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user