Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache #25

Merged
merged 11 commits into from
Apr 10, 2024
Merged
165 changes: 161 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ repository = "https://github.com/norskeld/arx"
publish = false

[dependencies]
base32 = "0.4.0"
chrono = "0.4.35"
clap = { version = "4.4.11", features = ["cargo", "derive"] }
crossterm = "0.27.0"
flate2 = { version = "1.0.28" }
git2 = { version = "0.18.1", features = ["vendored-libgit2"] }
glob-match = { version = "0.2.1" }
home = "0.5.9"
indicatif = "0.17.8"
inquire = { version = "0.7.0", features = ["editor"] }
kdl = "=4.6.0"
miette = { version = "=5.10.0", features = ["fancy"] }
reqwest = { version = "0.11.22", features = ["json"] }
run_script = { version = "0.10.1" }
serde = { version = "1.0.197", features = ["derive"] }
tar = { version = "0.4.40" }
thiserror = { version = "1.0.51" }
tokio = { version = "1.35.0", features = ["macros", "fs", "rt-multi-thread"] }
toml = "0.8.11"
unindent = "0.2.3"
walkdir = { version = "2.4.0" }

Expand Down
23 changes: 19 additions & 4 deletions src/actions/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Run {
.name
.clone()
.or_else(|| {
let lines = command.trim().lines().count();
let lines = command.lines().count();

if lines > 1 {
Some(command.trim().lines().next().unwrap().to_string() + "...")
Expand Down Expand Up @@ -277,10 +277,25 @@ impl Run {

if has_failed {
if !err.is_empty() {
eprintln!("{err}");
// Multiline scripts are run using a temporary shell script, so the errror messages
// sometimes don't look nice, containing the absolute path to that temporary script, e.g.:
//
// /var/folders/81/48f1l9956vjfqzmf9yy24g1c0000gn/T/fsio_1iyUIEI1GJ.sh: line 2: <error>
//
// So here I'm doing dirty string manipulation to clean up the message a bit.
let message = if let Some((_, trailing)) = err.split_once(".sh:") {
trailing.trim().to_string()
}
// TODO: Check error messages on windows (e.g. when trying to run a non-existing command),
// and clean up the message if necessary as well.
else {
err
};

eprintln!("{message}");
}

process::exit(1);
process::exit(code);
}

Ok(println!("{}", output.trim()))
Expand Down Expand Up @@ -380,7 +395,7 @@ impl Replace {
"✗".red()
};

println!("└─ {state} {replacement}");
println!("└─ {state} {replacement}");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/actions/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Executor {
match &self.config.actions {
| Actions::Suite(suites) => self.suite(suites).await?,
| Actions::Flat(actions) => self.flat(actions).await?,
| Actions::Empty => println!("No actions found."),
| Actions::Empty => return Ok(()),
};

// Delete the config file if needed.
Expand Down Expand Up @@ -105,6 +105,7 @@ impl Executor {
if !matches!(
(action, it.peek()),
(ActionSingle::Prompt(_), Some(ActionSingle::Prompt(_)))
| (ActionSingle::Unknown(_), Some(ActionSingle::Unknown(_)))
) {
println!();
}
Expand Down
5 changes: 2 additions & 3 deletions src/actions/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::process;
use crossterm::style::Stylize;
use inquire::formatter::StringFormatter;
use inquire::ui::{Color, RenderConfig, StyleSheet, Styled};
use inquire::{required, CustomType};
use inquire::{Confirm, Editor, InquireError, Select, Text};
use inquire::{Confirm, CustomType, Editor, InquireError, Select, Text};

use crate::actions::State;
use crate::config::prompts::*;
Expand Down Expand Up @@ -102,7 +101,7 @@ impl InputPrompt {
if let Some(default) = &self.default {
prompt = prompt.with_default(default);
} else {
prompt = prompt.with_validator(required!("This field is required."));
prompt = prompt.with_validator(inquire::required!("This field is required."));
}

match prompt.prompt() {
Expand Down
Loading
Loading