with sourcegraph as well

This commit is contained in:
Kasper Juul Hermansen 2022-12-17 22:56:07 +01:00
parent 6dc747f8b0
commit 51b54f83b6
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
8 changed files with 104 additions and 2 deletions

11
Cargo.lock generated
View File

@ -227,6 +227,16 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "sourcegraph"
version = "0.1.0"
dependencies = [
"clap",
"dirs",
"eyre",
"util",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"
@ -290,6 +300,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"eyre", "eyre",
"sourcegraph",
"tldr", "tldr",
"util", "util",
] ]

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[workspace] [workspace]
members = ["crates/tldr", "crates/util"] members = ["crates/tldr", "crates/util", "crates/sourcegraph"]
[workspace.dependencies] [workspace.dependencies]
clap = { version = "4.0.29", features = ["cargo"] } clap = { version = "4.0.29", features = ["cargo"] }
@ -16,6 +16,7 @@ walkdir = "2.3.2"
[dependencies] [dependencies]
tldr = { path = "crates/tldr" } tldr = { path = "crates/tldr" }
sourcegraph = { path = "crates/sourcegraph" }
util = { path = "crates/util" } util = { path = "crates/util" }
clap.workspace = true clap.workspace = true

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(())
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 KiB

View File

@ -5,12 +5,17 @@ mod prereqs;
fn main() -> eyre::Result<()> { fn main() -> eyre::Result<()> {
let matches = clap::Command::new("toolkit") let matches = clap::Command::new("toolkit")
.subcommands([prereqs::prereqs()?, tldr::Tldr::cmd()?]) .subcommands([
prereqs::prereqs()?,
tldr::Tldr::cmd()?,
sourcegraph::Sourcegraph::cmd()?,
])
.get_matches(); .get_matches();
match matches.subcommand() { match matches.subcommand() {
Some(("prereqs", subcmd)) => prereqs_exec(subcmd), Some(("prereqs", subcmd)) => prereqs_exec(subcmd),
Some(("tldr", subcmd)) => tldr::Tldr::exec(subcmd), Some(("tldr", subcmd)) => tldr::Tldr::exec(subcmd),
Some(("sourcegraph", subcmd)) => sourcegraph::Sourcegraph::exec(subcmd),
_ => Err(eyre::anyhow!("no command selected!")), _ => Err(eyre::anyhow!("no command selected!")),
} }
} }