Start run command

This commit is contained in:
SkyfallWasTaken 2024-07-09 21:39:58 +01:00
parent 450e02e54b
commit 4db902d286
4 changed files with 105 additions and 2 deletions

76
Cargo.lock generated
View file

@ -17,6 +17,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.14" version = "0.6.14"
@ -231,6 +240,9 @@ dependencies = [
"clap", "clap",
"color-eyre", "color-eyre",
"dinopkg-package-json", "dinopkg-package-json",
"env_logger",
"exitcode",
"log",
"owo-colors 4.0.0", "owo-colors 4.0.0",
"reqwest", "reqwest",
"tokio", "tokio",
@ -255,6 +267,29 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "env_filter"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -271,6 +306,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "exitcode"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
[[package]] [[package]]
name = "eyre" name = "eyre"
version = "0.6.12" version = "0.6.12"
@ -450,6 +491,12 @@ version = "1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "1.4.1" version = "1.4.1"
@ -792,6 +839,35 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "regex"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.12.5" version = "0.12.5"

View file

@ -12,3 +12,6 @@ tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }
dinopkg-package-json = { path = "../dinopkg-package-json", features = [ dinopkg-package-json = { path = "../dinopkg-package-json", features = [
"tokio", "tokio",
] } ] }
exitcode = "1.1.2"
log = "0.4.22"
env_logger = "0.11.3"

View file

@ -1,8 +1,26 @@
use color_eyre::Result; use color_eyre::{eyre::eyre, Result};
use dinopkg_package_json::PackageJson; use dinopkg_package_json::PackageJson;
use owo_colors::OwoColorize;
pub async fn run(script_name: Option<String>) -> Result<()> { pub async fn run(script_name: Option<String>) -> Result<()> {
let package_json = PackageJson::from_file(10).await?; let package_json = PackageJson::from_file(10).await?;
println!("Running script: {:?} {}", script_name, package_json.name);
match script_name {
Some(script_name) => {
let Some(scripts) = package_json.scripts else {
return Err(eyre!("no `scripts` provided in package.json"));
};
match scripts.get(&script_name) {
Some(script) => {
log::info!("{script_name}: {script}")
}
_ => return Err(eyre!(format!("script `{script_name}` not found"))),
}
}
_ => {
todo!()
}
}
Ok(()) Ok(())
} }

View file

@ -1,4 +1,5 @@
use clap::Parser; use clap::Parser;
use env_logger::{Builder, Env};
mod command; mod command;
use color_eyre::Result; use color_eyre::Result;
@ -6,6 +7,11 @@ use command::{Cli, Command};
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let env = Env::new()
.filter("DINOPKG_LOG")
.write_style("DINOPKG_LOG_STYLE");
env_logger::try_init_from_env(env)?;
let cli = Cli::parse(); let cli = Cli::parse();
match cli.command { match cli.command {
Command::Run { script_name } => command::run::run(script_name).await?, Command::Run { script_name } => command::run::run(script_name).await?,