Use --discard

This commit is contained in:
sxyazi 2026-03-20 15:19:22 +08:00
parent 82f4222385
commit 1dbf9f3f98
No known key found for this signature in database
9 changed files with 30 additions and 30 deletions

View file

@ -77,16 +77,16 @@ pub(super) enum CommandPkg {
Delete {
/// Packages to delete.
#[arg(index = 1, num_args = 1..)]
ids: Vec<String>,
/// Overwrite any local changes made to packages.
ids: Vec<String>,
/// Discard any local changes made to packages.
#[arg(long)]
overwrite: bool,
discard: bool,
},
/// Install all packages.
Install {
/// Overwrite any local changes made to packages.
/// Discard any local changes made to packages.
#[arg(long)]
overwrite: bool,
discard: bool,
},
/// List all packages.
List,
@ -94,10 +94,10 @@ pub(super) enum CommandPkg {
Upgrade {
/// Packages to upgrade, upgrade all if unspecified.
#[arg(index = 1, num_args = 0..)]
ids: Vec<String>,
/// Overwrite any local changes made to packages.
ids: Vec<String>,
/// Discard any local changes made to packages.
#[arg(short, long)]
overwrite: bool,
discard: bool,
},
}

View file

@ -78,10 +78,10 @@ async fn run() -> anyhow::Result<()> {
let mut pkg = package::Package::load().await?;
match cmd {
CommandPkg::Add { ids } => pkg.add_many(&ids).await?,
CommandPkg::Delete { ids, overwrite } => pkg.delete_many(&ids, overwrite).await?,
CommandPkg::Install { overwrite } => pkg.install(overwrite).await?,
CommandPkg::Delete { ids, discard } => pkg.delete_many(&ids, discard).await?,
CommandPkg::Install { discard } => pkg.install(discard).await?,
CommandPkg::List => pkg.print()?,
CommandPkg::Upgrade { ids, overwrite } => pkg.upgrade_many(&ids, overwrite).await?,
CommandPkg::Upgrade { ids, discard } => pkg.upgrade_many(&ids, discard).await?,
}
}

View file

@ -4,7 +4,7 @@ use super::{Dependency, Git};
use crate::shared::must_exists;
impl Dependency {
pub(super) async fn add(&mut self, overwrite: bool) -> Result<()> {
pub(super) async fn add(&mut self, discard: bool) -> Result<()> {
self.header("Upgrading package `{name}`")?;
let path = self.local();
@ -14,7 +14,7 @@ impl Dependency {
Git::clone(&self.remote(), &path).await?;
};
self.deploy(overwrite).await?;
self.deploy(discard).await?;
self.rev = Git::revision(&path).await?;
Ok(())
}

View file

@ -6,13 +6,13 @@ use super::Dependency;
use crate::shared::{maybe_exists, remove_sealed};
impl Dependency {
pub(super) async fn delete(&self, overwrite: bool) -> Result<()> {
pub(super) async fn delete(&self, discard: bool) -> Result<()> {
self.header("Deleting package `{name}`")?;
let dir = self.target();
if !maybe_exists(&dir).await {
return Ok(outln!("Not found, skipping")?);
} else if !overwrite {
} else if !discard {
self.hash_check().await?;
}

View file

@ -8,7 +8,7 @@ use super::Dependency;
use crate::shared::{copy_and_seal, maybe_exists};
impl Dependency {
pub(super) async fn deploy(&mut self, overwrite: bool) -> Result<()> {
pub(super) async fn deploy(&mut self, discard: bool) -> Result<()> {
let from = self.local().join(&self.child);
self.header("Deploying package `{name}`")?;
@ -16,7 +16,7 @@ impl Dependency {
let to = self.target();
let exists = maybe_exists(&to).await;
if exists && !overwrite {
if exists && !discard {
self.hash_check().await?;
}

View file

@ -46,7 +46,7 @@ impl Dependency {
if self.hash != self.hash().await? {
bail!(
"You have modified the contents of the `{}` {}. For safety, the operation has been aborted.
Please manually delete it from `{}` and re-run the command, or add `--overwrite` to overwrite any local changes.",
Please manually delete it from `{}` and re-run the command, or add `--discard` to discard any local changes.",
self.name,
if self.is_flavor { "flavor" } else { "plugin" },
self.target().display()

View file

@ -4,7 +4,7 @@ use super::{Dependency, Git};
use crate::shared::must_exists;
impl Dependency {
pub(super) async fn install(&mut self, overwrite: bool) -> Result<()> {
pub(super) async fn install(&mut self, discard: bool) -> Result<()> {
self.header("Fetching package `{name}`")?;
let path = self.local();
@ -18,7 +18,7 @@ impl Dependency {
Git::checkout(&path, self.rev.trim_start_matches('=')).await?;
}
self.deploy(overwrite).await?;
self.deploy(discard).await?;
if self.rev.is_empty() {
self.rev = Git::revision(&path).await?;
}

View file

@ -28,19 +28,19 @@ impl Package {
Ok(())
}
pub(crate) async fn delete_many(&mut self, uses: &[String], overwrite: bool) -> Result<()> {
pub(crate) async fn delete_many(&mut self, uses: &[String], discard: bool) -> Result<()> {
for u in uses {
let r = self.delete(u, overwrite).await;
let r = self.delete(u, discard).await;
self.save().await?;
r?;
}
Ok(())
}
pub(crate) async fn install(&mut self, overwrite: bool) -> Result<()> {
pub(crate) async fn install(&mut self, discard: bool) -> Result<()> {
macro_rules! go {
($dep:expr) => {
let r = $dep.install(overwrite).await;
let r = $dep.install(discard).await;
self.save().await?;
r?;
};
@ -55,11 +55,11 @@ impl Package {
Ok(())
}
pub(crate) async fn upgrade_many(&mut self, uses: &[String], overwrite: bool) -> Result<()> {
pub(crate) async fn upgrade_many(&mut self, uses: &[String], discard: bool) -> Result<()> {
macro_rules! go {
($dep:expr) => {
if uses.is_empty() || uses.contains(&$dep.r#use) {
let r = $dep.upgrade(overwrite).await;
let r = $dep.upgrade(discard).await;
self.save().await?;
r?;
}
@ -116,12 +116,12 @@ impl Package {
Ok(())
}
async fn delete(&mut self, r#use: &str, overwrite: bool) -> Result<()> {
async fn delete(&mut self, r#use: &str, discard: bool) -> Result<()> {
let Some(dep) = self.identical(&Dependency::from_str(r#use)?).cloned() else {
bail!("`{}` was not found in package.toml", r#use)
};
dep.delete(overwrite).await?;
dep.delete(discard).await?;
if dep.is_flavor {
self.flavors.retain(|d| !d.identical(&dep));
} else {

View file

@ -3,7 +3,7 @@ use anyhow::Result;
use super::Dependency;
impl Dependency {
pub(super) async fn upgrade(&mut self, overwrite: bool) -> Result<()> {
if self.rev.starts_with('=') { Ok(()) } else { self.add(overwrite).await }
pub(super) async fn upgrade(&mut self, discard: bool) -> Result<()> {
if self.rev.starts_with('=') { Ok(()) } else { self.add(discard).await }
}
}