-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters