with sourcegraph as well
This commit is contained in:
parent
6dc747f8b0
commit
51b54f83b6
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -227,6 +227,16 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sourcegraph"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
"eyre",
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
@ -290,6 +300,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"eyre",
|
||||
"sourcegraph",
|
||||
"tldr",
|
||||
"util",
|
||||
]
|
||||
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
members = ["crates/tldr", "crates/util"]
|
||||
members = ["crates/tldr", "crates/util", "crates/sourcegraph"]
|
||||
|
||||
[workspace.dependencies]
|
||||
clap = { version = "4.0.29", features = ["cargo"] }
|
||||
@ -16,6 +16,7 @@ walkdir = "2.3.2"
|
||||
|
||||
[dependencies]
|
||||
tldr = { path = "crates/tldr" }
|
||||
sourcegraph = { path = "crates/sourcegraph" }
|
||||
util = { path = "crates/util" }
|
||||
|
||||
clap.workspace = true
|
||||
|
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(())
|
||||
}
|
||||
}
|
BIN
output.gif
BIN
output.gif
Binary file not shown.
Before Width: | Height: | Size: 389 KiB |
@ -5,12 +5,17 @@ mod prereqs;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
let matches = clap::Command::new("toolkit")
|
||||
.subcommands([prereqs::prereqs()?, tldr::Tldr::cmd()?])
|
||||
.subcommands([
|
||||
prereqs::prereqs()?,
|
||||
tldr::Tldr::cmd()?,
|
||||
sourcegraph::Sourcegraph::cmd()?,
|
||||
])
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
Some(("prereqs", subcmd)) => prereqs_exec(subcmd),
|
||||
Some(("tldr", subcmd)) => tldr::Tldr::exec(subcmd),
|
||||
Some(("sourcegraph", subcmd)) => sourcegraph::Sourcegraph::exec(subcmd),
|
||||
_ => Err(eyre::anyhow!("no command selected!")),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user