Skip to content

Commit

Permalink
Replace '--reinstall' flag from 'install' by 'reinstall' action
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Dec 29, 2024
1 parent 4fa99be commit 4c5beda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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 = "fetchy"
version = "0.13.12"
version = "0.13.13"
edition = "2021"
description = "Quick packages installer"
license = "Apache-2.0"
Expand Down
12 changes: 6 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ pub enum Action {
#[clap(help = "Name of the package(s) to install", required = true)]
names: Vec<String>,

// #[clap(short, long, help = "Install from a specific repository")]
// repo: Option<String>,
//
#[clap(short, long, help = "Reinstall the package(s) if already installed")]
reinstall: bool,

#[clap(
short,
long,
Expand All @@ -40,6 +34,12 @@ pub enum Action {
discreet: bool,
},

#[clap(about = "Re-install some already-installed package(s)")]
Reinstall {
#[clap(help = "Name of the package(s) to reinstall", required = true)]
names: Vec<String>,
},

#[clap(about = "Update package(s)")]
Update {
#[clap(help = "Only update some package(s)")]
Expand Down
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,14 @@ async fn inner(action: Action) -> Result<()> {
match action {
Action::Install {
names,
reinstall,
check_updates,
discreet,
} => {
let pkgs = resolve_pkgs_by_name_with_deps(names.as_slice(), &repos)?;

install_pkgs(
pkgs,
if reinstall {
InstalledPackagesHandling::Reinstall
} else if check_updates {
if check_updates {
InstalledPackagesHandling::CheckUpdates
} else {
InstalledPackagesHandling::Ignore
Expand All @@ -112,6 +109,18 @@ async fn inner(action: Action) -> Result<()> {
.await?;
}

Action::Reinstall { names } => {
let pkgs = resolve_installed_pkgs_by_name(&names, &db.installed, &repos)?;

let pkgs = pkgs
.into_iter()
.map(|(resolved, _)| resolved)
.map(refresh_pkg)
.collect::<Result<Vec<_>, _>>()?;

install_pkgs(pkgs, InstalledPackagesHandling::Reinstall, &mut db, false).await?;
}

Action::Update { names } => {
let pkgs = if !names.is_empty() {
resolve_installed_pkgs_by_name(&names, &db.installed, &repos)?
Expand Down

0 comments on commit 4c5beda

Please sign in to comment.