Skip to content

Commit

Permalink
feat[#4]: update command
Browse files Browse the repository at this point in the history
  • Loading branch information
zfwf committed Jan 6, 2024
1 parent fa3074f commit 1d080ff
Show file tree
Hide file tree
Showing 26 changed files with 646 additions and 369 deletions.
136 changes: 103 additions & 33 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ exclude = [".gitignore", "*.yml", "tests/**"]
rand = "0.8"
# error handling
eyre = "0.6"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
serde = { version = "1.0.195", features = ["derive"] }
serde_yaml = "0.9.30"
regex = "1.4"
reqwest = { version = "0.11", features = ["blocking", "json"] }

Expand All @@ -32,6 +32,7 @@ env_logger = "0.9"

tokio = "1.24.1"
clap = { version = "4.2.1", features = ["derive"] }
time = {version = "0.3.31", features = ["local-offset", "formatting"]}

[dev-dependencies]

1 change: 0 additions & 1 deletion src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pub mod load;
pub mod make;
pub mod resource;
pub mod src;
pub mod update;
10 changes: 5 additions & 5 deletions src/hooks/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn extract(
current_shell: &SupportedShell,
cmd: &str,
) -> Result<(), Box<dyn std::error::Error>> {
run_cmd(current_shell, &cmd)?;
run_cmd_in_shell(current_shell, &cmd)?;

Check failure on line 10 in src/hooks/extract.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/hooks/extract.rs#L10

error: this expression creates a reference which is immediately dereferenced by the compiler --> src/hooks/extract.rs:10:37 | 10 | run_cmd_in_shell(current_shell, &cmd)?; | ^^^^ help: change this to: `cmd` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`
Raw output
src/hooks/extract.rs:10:37:e:error: this expression creates a reference which is immediately dereferenced by the compiler
  --> src/hooks/extract.rs:10:37
   |
10 |     run_cmd_in_shell(current_shell, &cmd)?;
   |                                     ^^^^ help: change this to: `cmd`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `-D clippy::needless-borrow` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`


__END__

Ok(())
}
Expand All @@ -21,13 +21,13 @@ pub fn extract_asset(
if let Some(kind) = &infer_kind {
match kind.extension() {
"zip" => {
run_cmd(current_shell, &format!("unzip {}", asset_path_string))?;
run_cmd_in_shell(current_shell, &format!("unzip {}", asset_path_string))?;
}
"gz" => {
run_cmd(current_shell, &format!("tar xvf {}", asset_path_string))?;
run_cmd_in_shell(current_shell, &format!("tar xvf {}", asset_path_string))?;
}
"deb" => {
run_cmd(
run_cmd_in_shell(
current_shell,
&format!(
"ar xv {}; ls *.tar.* | xargs -n 1 tar xvf",
Expand All @@ -41,7 +41,7 @@ pub fn extract_asset(
println!("ext {:?}", ext);
match ext.to_str().unwrap() {
"dmg" => {
run_cmd(
run_cmd_in_shell(
current_shell,
&format!(
r#"
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ pub fn init(
init_cmd: &ShellSpecificCommand,
) -> Result<String, Box<dyn std::error::Error>> {
match init_cmd {
ShellSpecificCommand::Generic(generic) => run_cmd_with_output(current_shell, generic),
ShellSpecificCommand::Generic(generic) => {
run_cmd_in_shell_with_output(current_shell, generic)
}
ShellSpecificCommand::ShellSpecific(shell_specific) => {
run_shell_cmd(current_shell, shell_specific)
run_shell_specific_cmd(current_shell, shell_specific)
}
}
}
6 changes: 4 additions & 2 deletions src/hooks/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ pub fn install(
install_cmd: &ShellSpecificCommand,
) -> Result<String, Box<dyn std::error::Error>> {
match install_cmd {
ShellSpecificCommand::Generic(generic) => run_cmd_with_output(current_shell, generic),
ShellSpecificCommand::Generic(generic) => {
run_cmd_in_shell_with_output(current_shell, generic)
}
ShellSpecificCommand::ShellSpecific(shell_specific) => {
run_shell_cmd(current_shell, shell_specific)
run_shell_specific_cmd(current_shell, shell_specific)
}
}
}
25 changes: 5 additions & 20 deletions src/hooks/load.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
use crate::utils::{config::ShellSpecificEvaluatable, shells::SupportedShell};
use crate::utils::{
config::ShellSpecificEvaluatable, evaluatable::process_evaluatable, shells::SupportedShell,
};

pub fn load(
current_shell: &SupportedShell,
load_cmd: &ShellSpecificEvaluatable,
load_evaluatable: &ShellSpecificEvaluatable,
) -> Result<(), Box<dyn std::error::Error>> {
Ok(match load_cmd {
ShellSpecificEvaluatable::Generic(generic) => println!("{}", generic),
ShellSpecificEvaluatable::ShellSpecific(shell_specific) => {
let shell_specific_evaluatable = match current_shell {
SupportedShell::Sh => &shell_specific.sh,
SupportedShell::Bash => &shell_specific.bash,
SupportedShell::Zsh => &shell_specific.zsh,
SupportedShell::Fish => &shell_specific.fish,
SupportedShell::PowerShell => &shell_specific.powershell,
SupportedShell::WinCmd => &shell_specific.wincmd,
};

match shell_specific_evaluatable {
Some(evaluatable) => println!("{}", evaluatable),
None => (),
}
}
})
process_evaluatable(current_shell, load_evaluatable)
}
Loading

0 comments on commit 1d080ff

Please sign in to comment.