with network stats
This commit is contained in:
parent
f8d2351538
commit
94f254047f
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -247,6 +247,16 @@ dependencies = [
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stats"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
"eyre",
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
@ -312,6 +322,7 @@ dependencies = [
|
||||
"eyre",
|
||||
"github",
|
||||
"sourcegraph",
|
||||
"stats",
|
||||
"tldr",
|
||||
"util",
|
||||
]
|
||||
|
@ -4,7 +4,13 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
members = ["crates/tldr", "crates/util", "crates/sourcegraph", "crates/github"]
|
||||
members = [
|
||||
"crates/tldr",
|
||||
"crates/util",
|
||||
"crates/sourcegraph",
|
||||
"crates/github",
|
||||
"crates/stats",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
clap = { version = "4.0.29", features = ["cargo"] }
|
||||
@ -19,6 +25,7 @@ github = { path = "crates/github" }
|
||||
tldr = { path = "crates/tldr" }
|
||||
sourcegraph = { path = "crates/sourcegraph" }
|
||||
util = { path = "crates/util" }
|
||||
stats = { path = "crates/stats" }
|
||||
|
||||
clap.workspace = true
|
||||
eyre.workspace = true
|
||||
|
13
crates/stats/Cargo.toml
Normal file
13
crates/stats/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "stats"
|
||||
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
|
58
crates/stats/src/code.rs
Normal file
58
crates/stats/src/code.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use eyre::Context;
|
||||
|
||||
pub struct Code;
|
||||
|
||||
struct Settings {
|
||||
prefer_docker: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
prefer_docker: std::env::var("TOOLKIT_PREFER_DOCKER")
|
||||
.unwrap_or("false".into())
|
||||
.parse()
|
||||
.context("TOOLKIT_PREFER_DOCKER could not be parsed as a bool")
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Code {
|
||||
fn run() -> eyre::Result<()> {
|
||||
if Settings::new().prefer_docker {
|
||||
let current_dir = std::env::current_dir()?;
|
||||
let current_dir_str = current_dir
|
||||
.to_str()
|
||||
.ok_or(eyre::anyhow!("could not parse path as string"))?;
|
||||
util::shell::run(
|
||||
&[
|
||||
"docker",
|
||||
"run",
|
||||
"-v",
|
||||
&format!("{current_dir_str}:/mnt"),
|
||||
"kasperhermansen/tokei:12.1-amd64",
|
||||
],
|
||||
None,
|
||||
)?;
|
||||
} else {
|
||||
util::shell::run(&["tokei"], None)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl util::Cmd for Code {
|
||||
fn cmd() -> eyre::Result<clap::Command> {
|
||||
let cmd = clap::Command::new("code").subcommands(&[]);
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
|
||||
match args.subcommand() {
|
||||
_ => Code::run(),
|
||||
}
|
||||
}
|
||||
}
|
28
crates/stats/src/lib.rs
Normal file
28
crates/stats/src/lib.rs
Normal file
@ -0,0 +1,28 @@
|
||||
mod code;
|
||||
mod network;
|
||||
|
||||
pub struct Stats;
|
||||
|
||||
impl Stats {
|
||||
fn run() -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl util::Cmd for Stats {
|
||||
fn cmd() -> eyre::Result<clap::Command> {
|
||||
let cmd = clap::Command::new("stats")
|
||||
.subcommands(&[code::Code::cmd()?, network::Network::cmd()?])
|
||||
.subcommand_required(true);
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
|
||||
match args.subcommand() {
|
||||
Some(("code", args)) => code::Code::exec(args),
|
||||
Some(("network", args)) => network::Network::exec(args),
|
||||
_ => Stats::run(),
|
||||
}
|
||||
}
|
||||
}
|
66
crates/stats/src/network.rs
Normal file
66
crates/stats/src/network.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use eyre::Context;
|
||||
|
||||
struct Settings {
|
||||
prefer_docker: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
prefer_docker: std::env::var("TOOLKIT_PREFER_DOCKER")
|
||||
.unwrap_or("false".into())
|
||||
.parse()
|
||||
.context("TOOLKIT_PREFER_DOCKER could not be parsed as a bool")
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Network;
|
||||
|
||||
impl Network {
|
||||
fn run() -> eyre::Result<()> {
|
||||
if Settings::new().prefer_docker {
|
||||
// let current_dir = std::env::current_dir()?;
|
||||
// let current_dir_str = current_dir
|
||||
// .to_str()
|
||||
// .ok_or(eyre::anyhow!("could not parse path as string"))?;
|
||||
//util::shell::run(
|
||||
// &[
|
||||
// "docker",
|
||||
// "run",
|
||||
// "-v",
|
||||
// &format!("{current_dir_str}:/mnt"),
|
||||
// "kasperhermansen/tokei:12.1-amd64",
|
||||
// ],
|
||||
// None,
|
||||
//)?;
|
||||
} else {
|
||||
}
|
||||
if let Err(_) =
|
||||
util::shell::run_with_input_and_output(&["bandwhich", "--version"], "".into())
|
||||
{
|
||||
return Err(eyre::anyhow!(
|
||||
"could not find bandwhich, please install or add to PATH"
|
||||
));
|
||||
}
|
||||
|
||||
util::shell::run(&["bandwhich"], None)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl util::Cmd for Network {
|
||||
fn cmd() -> eyre::Result<clap::Command> {
|
||||
let cmd = clap::Command::new("network").subcommands(&[]);
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
|
||||
match args.subcommand() {
|
||||
_ => Network::run(),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
use prereqs::prereqs_exec;
|
||||
use util::Cmd;
|
||||
|
||||
mod prereqs;
|
||||
@ -10,14 +9,16 @@ fn main() -> eyre::Result<()> {
|
||||
tldr::Tldr::cmd()?,
|
||||
sourcegraph::Sourcegraph::cmd()?,
|
||||
github::GitHub::cmd()?,
|
||||
stats::Stats::cmd()?,
|
||||
])
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
Some(("prereqs", subcmd)) => prereqs_exec(subcmd),
|
||||
Some(("prereqs", subcmd)) => prereqs::prereqs_exec(subcmd),
|
||||
Some(("tldr", subcmd)) => tldr::Tldr::exec(subcmd),
|
||||
Some(("sourcegraph", subcmd)) => sourcegraph::Sourcegraph::exec(subcmd),
|
||||
Some(("github", subcmd)) => github::GitHub::exec(subcmd),
|
||||
Some(("stats", subcmd)) => stats::Stats::exec(subcmd),
|
||||
_ => Err(eyre::anyhow!("no command selected!")),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user