Skip to content

Commit

Permalink
Support scoop (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Sep 12, 2020
1 parent 7b6d3d5 commit 0e9dd31
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "upt"
version = "0.2.0"
version = "0.3.0"
authors = ["sigoden <[email protected]>"]
edition = "2018"
description = "Universal package management tool for Windows, MacOS, Linux"
Expand Down
1 change: 1 addition & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ brew install wget # upt可以像brew样工作
- [x] apt
- [x] brew
- [x] choco
- [x] scoop
- [x] dnf
- [x] pacman
- [x] yum
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl SubCommand {
} else {
options.remove(0)
}
},
}
false => {
if operands.len() == 0 {
String::new()
Expand Down
17 changes: 16 additions & 1 deletion src/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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;
mod brew;
mod choco;
mod dnf;
mod pacman;
mod scoop;
mod upt;
mod yum;

Expand Down Expand Up @@ -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(),
Expand All @@ -52,6 +56,9 @@ impl Vendor {
/// Detect package management on os
pub fn detect() -> Result<Vendor, UptError> {
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());
Expand Down Expand Up @@ -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::*;
Expand Down
13 changes: 13 additions & 0 deletions src/vendor/scoop.rs
Original file line number Diff line number Diff line change
@@ -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",
}

0 comments on commit 0e9dd31

Please sign in to comment.