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

View file

@ -12,3 +12,6 @@ tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }
dinopkg-package-json = { path = "../dinopkg-package-json", features = [
"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 owo_colors::OwoColorize;
pub async fn run(script_name: Option<String>) -> Result<()> {
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(())
}

View file

@ -1,4 +1,5 @@
use clap::Parser;
use env_logger::{Builder, Env};
mod command;
use color_eyre::Result;
@ -6,6 +7,11 @@ use command::{Cli, Command};
#[tokio::main]
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();
match cli.command {
Command::Run { script_name } => command::run::run(script_name).await?,