-
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.
refactor: remove syntax.rs and merge syntax into commands file
- Loading branch information
Showing
10 changed files
with
242 additions
and
242 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,11 +1,51 @@ | ||
use crate::syntax; | ||
use crate::root::get_sudo; | ||
|
||
pub fn list(manager: String) { | ||
let mut list_cmd = syntax::gen_list_syntax(manager.clone()) | ||
let mut list_cmd = gen_list_syntax(manager.clone()) | ||
.stdout(std::process::Stdio::inherit()) | ||
.stderr(std::process::Stdio::inherit()) | ||
.spawn() | ||
.expect("yu: Failed to execute command"); | ||
|
||
list_cmd.wait().expect("Command wasn't running"); | ||
} | ||
|
||
pub fn gen_list_syntax(manager: String) -> std::process::Command { | ||
let mut command: std::process::Command = get_sudo(manager.clone()); | ||
match manager.as_str() { | ||
"apt" => { | ||
command.arg("list"); | ||
command.arg("--installed"); | ||
} | ||
"dnf" => { | ||
command.arg("list"); | ||
command.arg("installed"); | ||
} | ||
"yum" => { | ||
command.arg("list"); | ||
command.arg("installed"); | ||
} | ||
"pacman" => { | ||
command.arg("-Q"); | ||
} | ||
"zypper" => { | ||
command.arg("search"); | ||
command.arg("--installed-only"); | ||
} | ||
"apk" => { | ||
command.arg("info"); | ||
command.arg("--installed"); | ||
} | ||
"portage" => { | ||
command.arg("--list"); | ||
command.arg("world"); | ||
} | ||
"brew" => { | ||
command.arg("list"); | ||
} | ||
_ => { | ||
println!("Unknown package manager: {}", manager); | ||
} | ||
} | ||
command | ||
} |
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
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 |
---|---|---|
@@ -1,14 +1,45 @@ | ||
use crate::syntax; | ||
use crate::root::get_sudo; | ||
|
||
pub fn update(manager: String, silent: bool, verbose: bool) { | ||
if !silent { | ||
println!("yu: Updating system"); | ||
} | ||
let mut update_cmd = syntax::gen_update_syntax(manager.clone()) | ||
let mut update_cmd = gen_update_syntax(manager.clone()) | ||
.stdout(if verbose { std::process::Stdio::inherit() } else { std::process::Stdio::null() }) | ||
.stderr(std::process::Stdio::inherit()) | ||
.spawn() | ||
.expect("Failed to execute update command"); | ||
|
||
update_cmd.wait().expect("Update command wasn't running"); | ||
} | ||
|
||
pub fn gen_update_syntax(manager: String) -> std::process::Command { | ||
let mut command: std::process::Command = get_sudo(manager.clone()); | ||
match manager.as_str() { | ||
"apt" => { | ||
command.arg("update"); | ||
} | ||
"dnf" | "yum" => { | ||
command.arg("check-update"); | ||
} | ||
"pacman" => { | ||
command.arg("-Sy"); | ||
} | ||
"zypper" => { | ||
command.arg("refresh"); | ||
} | ||
"apk" => { | ||
command.arg("update"); | ||
} | ||
"portage" => { | ||
command.arg("sync"); | ||
} | ||
"brew" => { | ||
command.arg("update"); | ||
} | ||
_ => { | ||
println!("Unknown package manager: {}", manager); | ||
} | ||
} | ||
command | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use clap::{Arg, Command}; | ||
|
||
mod env; | ||
mod syntax; | ||
mod root; | ||
|
||
mod command { | ||
pub mod info; | ||
|
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,12 @@ | ||
pub fn get_sudo(manager: String) -> std::process::Command { | ||
let command = match manager.as_str() { | ||
"apt" | "dnf" | "yum" | "pacman" | "zypper" | "apk" | "portage" => { | ||
let mut cmd = std::process::Command::new("sudo"); | ||
cmd.arg(manager.clone()); | ||
cmd | ||
} | ||
_ => std::process::Command::new(manager.clone()), | ||
}; | ||
|
||
command | ||
} |
Oops, something went wrong.