From 70e459a0111f55a3f1be3746baf64cbf68a68fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sat, 17 May 2025 15:58:40 +0800 Subject: [PATCH] feat: new `ya pkg` subcommand (#2770) --- yazi-cli/src/args.rs | 30 +++++++++++++++++++++++++++++- yazi-cli/src/main.rs | 16 ++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index c2a3a4d1..c8eb54aa 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -22,7 +22,11 @@ pub(super) enum Command { /// Emit a command to be executed by the specified instance. EmitTo(CommandEmitTo), /// Manage packages. - Pack(CommandPack), + #[command(subcommand)] + Pkg(CommandPkg), + #[command(hide = true)] + /// Manage packages. + Pack(CommandPack), // TODO: remove /// Publish a message to the current instance. Pub(CommandPub), /// Publish a message to the specified instance. @@ -51,6 +55,30 @@ pub(super) struct CommandEmitTo { pub(super) args: Vec, } +#[derive(Subcommand)] +pub(super) enum CommandPkg { + /// Add packages. + #[command(arg_required_else_help = true)] + Add { + /// The packages to add. + #[arg(index = 1, num_args = 1..)] + ids: Vec, + }, + /// Delete packages. + #[command(arg_required_else_help = true)] + Delete { + /// The packages to delete. + #[arg(index = 1, num_args = 1..)] + ids: Vec, + }, + /// Install all packages. + Install, + /// List all packages. + List, + /// Upgrade all packages. + Upgrade, +} + #[derive(clap::Args)] #[command(arg_required_else_help = true)] pub(super) struct CommandPack { diff --git a/yazi-cli/src/main.rs b/yazi-cli/src/main.rs index e0257f45..b77092e3 100644 --- a/yazi-cli/src/main.rs +++ b/yazi-cli/src/main.rs @@ -60,8 +60,24 @@ async fn run() -> anyhow::Result<()> { } } + Command::Pkg(cmd) => { + package::init()?; + + let mut pkg = package::Package::load().await?; + match cmd { + CommandPkg::Add { ids } => pkg.add_many(&ids).await?, + CommandPkg::Delete { ids } => pkg.delete_many(&ids).await?, + CommandPkg::Install => pkg.install(false).await?, + CommandPkg::List => pkg.print()?, + CommandPkg::Upgrade => pkg.install(true).await?, + } + } + Command::Pack(cmd) => { package::init()?; + outln!( + "WARNING: `ya pack` is deprecated, use the new `ya pkg` instead. See https://github.com/sxyazi/yazi/pull/2770 for more details." + )?; if cmd.install { package::Package::load().await?.install(false).await?; } else if cmd.list {