mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: new ya pkg subcommand (#2770)
This commit is contained in:
parent
358524347f
commit
70e459a011
2 changed files with 45 additions and 1 deletions
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
},
|
||||
/// Delete packages.
|
||||
#[command(arg_required_else_help = true)]
|
||||
Delete {
|
||||
/// The packages to delete.
|
||||
#[arg(index = 1, num_args = 1..)]
|
||||
ids: Vec<String>,
|
||||
},
|
||||
/// 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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue