17 个不稳定版本 (8 个破坏性更新)

0.21.0 2024年1月29日
0.20.1 2023年11月27日
0.20.0 2023年10月31日
0.19.2 2023年7月27日
0.13.2 2021年8月23日

#921 in 过程宏

每月下载量 23
pacaptr 中使用

GPL-3.0 许可证

11KB
188

pacaptr

pacaptr

Crates.io docs.rs Private APIs License

pac·apt·r,或称 PACman AdaPTeR,是许多包管理器的包装器,允许您使用 pacman 命令。

只需在非 Arch 操作系统上设置 pacmanpacaptr 的别名,然后您就可以在任何地方运行 pacman -Syu

> pacaptr -S neofetch
  Pending `brew reinstall neofetch`
  Proceed with the previous command? · Yes
  Running `brew reinstall neofetch`
==> Downloading https://homebrew.bintray.com/bottles/neofetch-7.1.0
########################################################### 100.0%
==> Reinstalling neofetch
==> Pouring neofetch-7.1.0.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/neofetch/7.1.0: 6 files, 351.7KB

为什么选择 pacaptr

我从 Arch Linux 迁移到 macOS,我真的很喜欢有一个自动化的 Pacman Rosetta,这使我能够通过简洁的 pacman 语法使常见的包管理任务变得不那么繁琐。

这就是我决定从现有的基于 shicy/pacapt 吸取灵感,用 Rust 编写一个新 CLI 工具的原因,以便更好地移植(尤其是针对 Windows 和 macOS)和更易于维护。

支持的包管理器

pacaptr 目前支持以下包管理器(按优先级顺序)

目前,优先级仍然是(不幸地)硬编码的。例如,如果同时安装了 scoopchoco,则默认使用 scoop。然而,您可以在您的 配置 中编辑默认的包管理器。

请参考 兼容性表 了解更多关于哪些操作被支持。

安装

注意 我们需要您的帮助 在更多平台上实现 pacaptr 的二进制分发!

Brew

Tap Updated

brew install rami3l/tap/pacaptr

Scoop

Scoop Version

scoop bucket add extras
scoop install pacaptr

Choco

Chocolatey Version Chocolatey Downloads

choco install pacaptr

Cargo

Cargo Version Cargo Downloads

如果您已安装 cargo-binstall,通过 cargo 安装 pacaptr 的最快方法是运行

cargo binstall pacaptr

从 crates.io 构建并安装发布版本

cargo install pacaptr

从 GitHub 构建并安装 master 版本

cargo install pacaptr --git https://github.com/rami3l/pacaptr.git

对于感兴趣的人,也可以从本地仓库构建和安装

git clone https://github.com/rami3l/pacaptr.git && cd pacaptr
cargo install --path .
# The output path is usually `$HOME/.cargo/bin/pacaptr`.

卸载

cargo uninstall pacaptr

对于 Alpine Linux 用户,cargo build 可能不会工作。请尝试以下操作

RUSTFLAGS="-C target-feature=-crt-static" cargo build

为 Debian 打包

cargo install cargo-deb
cargo deb

配置

以下优先级定义了配置文件路径

  • $PACAPTR_CONFIG,如果已设置;
  • $XDG_CONFIG_HOME/pacaptr/pacaptr.toml,如果 $XDG_CONFIG_HOME 已设置;
  • $HOME/.config/pacaptr/pacaptr.toml.

我决定不未经用户同意就丢弃用户的 $HOME,因此

  • 如果用户尚未指定任何路径,我们将查找默认路径中的配置文件。

  • 如果配置文件无论如何都不存在,将使用 Default::default 加载默认配置,并且不会写入任何文件。

  • 任何配置项都可以被相应的 PACAPTR_* 环境变量覆盖。例如,PACAPTR_NEEDED=falsepacaptr.toml 中优先于 needed = true

示例
# This enforces the use of `install` instead of
# `reinstall` in `pacaptr -S`
needed = true

# Explicitly set the default package manager
default_pm = "choco"

# dry_run = false
# no_confirm = false
# no_cache = false

提示

通用

--using--pm

使用此标志可以显式指定要调用的底层包管理器。

# Here we force the use of `choco`,
# so the following output is platform-independent:
pacaptr --using choco -Su --dryrun
# Canceled: choco upgrade all

这在您运行 Linux 并想使用 linuxbrew 等情况时非常有用。在这种情况下,您可以使用 --using brew

自动调用 sudo

如果您不是 root 并且希望执行需要 sudo 的操作,pacaptr 会通过调用 sudo -S 来为您执行。

此功能目前适用于以下包管理器:apkaptdnfemergepkconportxbpszypper

额外标志支持

位于 -- 之后的所有标志将直接传递给底层包管理器

pacaptr -h
# USAGE:
#     pacaptr [FLAGS] [KEYWORDS]... [-- <EXTRA_FLAGS>...]

pacaptr -S curl docker --dryrun -- --proxy=localhost:1234
# Canceled: foo install curl --proxy=localhost:1234
# Canceled: foo install docker --proxy=localhost:1234

这里 foo 是您的包管理器名称。(实际输出是平台特定的,这主要取决于 foo 是否能够实际读取给出的标志。)

--dryrun--dry-run

使用此标志仅打印要执行的命令(有时与 --dry-run 标志一起使用以激活包管理器的 dryrun 选项)。

Pending 表示命令执行已被提示阻塞;Canceled 表示在 dry run 中已取消;Running 表示它已经开始运行。

可能仍会运行一些查询命令,但任何“大”操作都应该已经停止,例如安装。例如

# Nothing will be installed,
# as `brew install curl` won't run:
pacaptr -S curl --dryrun
# Canceled: brew install curl

# Nothing will be deleted here,
# but `brew cleanup --dry-run` is actually running:
pacaptr -Sc --dryrun
# Running: brew cleanup --dry-run
# .. (showing the files to be removed)

# To remove the forementioned files,
# run the command above again without `--dryrun`:
pacaptr -Sc
# Running: brew cleanup
# .. (cleaning up)

--yes--noconfirm--no-confirm

使用此标志触发您的包管理器对应的标志(如果可能)以回答“是”给所有进入的问题。

此选项在您不希望在安装期间被询问时很有用,例如,但如果不了解自己在做什么,它也可能很危险!

--nocache--no-cache

使用此标志在安装包后删除缓存。

此选项在您想减小 Docker 镜像大小时很有用。

平台特定提示

对于 brew

  • 请注意,cask 仅供 macOS 使用。

  • 当公式和 cask 具有相同名称时请小心,例如 docker

    pacaptr -Si docker | rg cask
    # => Warning: Treating docker as a formula. For the cask, use homebrew/cask/docker
    
    # Install the formula `docker`
    pacaptr -S docker
    
    # Install the cask `docker`
    pacaptr -S homebrew/cask/docker
    
    # Make homebrew treat all keywords as casks
    pacaptr -S docker -- --cask
    

对于 scoop

  • pacaptr 启动一个 pwsh 子进程来运行 scoop,如果 pwsh 未在 $PATH 中找到,则运行一个 powershell 子进程。请确保您已在相应的 shell 中设置了正确的执行策略。

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    

对于 choco

  • 不要忘记在提升的 shell 中运行!您可以使用像 gsudo 这样的工具轻松完成此操作。

对于 pip

  • 如果您想运行 pip3 命令,请使用 pacaptr --using pip3

想要贡献吗?

听起来不错!请让我带您到 贡献指南 :)

依赖项

~4.5–6MB
~110K SLoC