From 0e9dd3181af0599345633b934a779d7c51fb875c Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 12 Sep 2020 18:57:36 +0800 Subject: [PATCH] Support scoop (#5) --- Cargo.lock | 3 +-- Cargo.toml | 2 +- README-zh_CN.md | 1 + README.md | 1 + src/subcommand.rs | 2 +- src/vendor.rs | 17 ++++++++++++++++- src/vendor/scoop.rs | 13 +++++++++++++ 7 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/vendor/scoop.rs diff --git a/Cargo.lock b/Cargo.lock index 21612fe..fdbcf78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,5 +2,4 @@ # It is not intended for manual editing. [[package]] name = "upt" -version = "0.2.0" - +version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 82c87b6..d41ee0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "upt" -version = "0.2.0" +version = "0.3.0" authors = ["sigoden "] edition = "2018" description = "Universal package management tool for Windows, MacOS, Linux" diff --git a/README-zh_CN.md b/README-zh_CN.md index e9de03d..0699544 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -55,6 +55,7 @@ brew install wget # upt可以像brew样工作 - [x] apt - [x] brew - [x] choco +- [x] scoop - [x] dnf - [x] pacman - [x] yum diff --git a/README.md b/README.md index df50463..c3d19ea 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ brew install wget # upt will work like brew - [x] apt - [x] brew - [x] choco +- [x] scoop - [x] dnf - [x] pacman - [x] yum diff --git a/src/subcommand.rs b/src/subcommand.rs index 3d7264c..401a417 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -130,7 +130,7 @@ impl SubCommand { } else { options.remove(0) } - }, + } false => { if operands.len() == 0 { String::new() diff --git a/src/vendor.rs b/src/vendor.rs index be3aea9..1cfd9c5 100644 --- a/src/vendor.rs +++ b/src/vendor.rs @@ -1,7 +1,9 @@ +use std::fs; +use std::process::{Command, Stdio}; + use crate::error::UptError; use crate::subcommand::SubCommand; use crate::task::Task; -use std::fs; mod apk; mod apt; @@ -9,6 +11,7 @@ mod brew; mod choco; mod dnf; mod pacman; +mod scoop; mod upt; mod yum; @@ -41,6 +44,7 @@ impl Vendor { "apt" => apt::init(), "brew" => brew::init(), "choco" => choco::init(), + "scoop" => scoop::init(), "dnf" => dnf::init(), "pacman" => pacman::init(), "upt" => upt::init(), @@ -52,6 +56,9 @@ impl Vendor { /// Detect package management on os pub fn detect() -> Result { if cfg!(target_os = "windows") { + if which("scoop") { + return Ok(scoop::init()); + } return Ok(choco::init()); } else if cfg!(target_os = "macos") { return Ok(brew::init()); @@ -188,6 +195,14 @@ impl Vendor { } } +fn which(name: &str) -> bool { + Command::new(name) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .is_ok() +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/vendor/scoop.rs b/src/vendor/scoop.rs new file mode 100644 index 0000000..9dd0fff --- /dev/null +++ b/src/vendor/scoop.rs @@ -0,0 +1,13 @@ +vendor! { + name: "scoop", + yes: [], + install: "install $", + remove: "uninstall $", + upgrade: "update $", + search: "search $", + show: "info $", + update_index: "update", + upgrade_all: "update *", + list_upgradable: "list", + list_installed: "list", +}