rami3l / pacaptr

Pacman-like syntax wrapper for many package managers.
https://crates.io/crates/pacaptr
GNU General Public License v3.0
369 stars 10 forks source link

[Bug] `--using`/`--pm` don't do anything if overridden by a config file #677

Closed 00-kat closed 9 months ago

00-kat commented 9 months ago

Issue

Trying to use the --using or the --pm options to change the package manager have to effect if the setting is overridden by a config.toml. I'm on Windows 10.

My config file (at ~\.config\pacaptr\pacaptr.toml looks like this:

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

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

Expected Outcome

Using the --using or the --pm options changes the package manager (unless I'm using them wrong):

PowerShell 7.4.1
PS user@hostname:C:\Users\user> pacaptr -V
pacaptr v0.20.1
PS user@hostname:C:\Users\user> sudo pacaptr --using choco -Ss fastfetch
  Running `choco search fastfetch`
Chocolatey v2.2.2
0 packages found.
PS user@hostname:C:\Users\user> pacaptr --using scoop -Ss fastfetch
  Running `scoop search fastfetch`
Results from local buckets...

Name      Version Source Binaries
----      ------- ------ --------
fastfetch 2.7.0   main

PS user@hostname:C:\Users\user> pacaptr -Ss fastfetch
  Running `winget search --accept-source-agreements fastfetch`
No package found matching input criteria.
    Error Subprocess exited with code -1978335212

Actual Outcome

When I try to use Chocolatey or Scoop instead, it still runs Winget (P.S. Scoop has a package named fastfetch, while Chocolatey and Winget don't):

PowerShell 7.4.1
PS user@hostname:C:\Users\user> pacaptr -V
pacaptr v0.20.1
PS user@hostname:C:\Users\user> sudo pacaptr --using choco -Ss fastfetch
  Running `winget search --accept-source-agreements fastfetch`
No package found matching input criteria.
    Error Subprocess exited with code -1978335212
PS user@hostname:C:\Users\user> pacaptr --using scoop -Ss fastfetch
  Running `winget search --accept-source-agreements fastfetch`
No package found matching input criteria.
    Error Subprocess exited with code -1978335212
PS user@hostname:C:\Users\user> pacaptr -Ss fastfetch
  Running `winget search --accept-source-agreements fastfetch`
No package found matching input criteria.
    Error Subprocess exited with code -1978335212
rami3l commented 9 months ago

@cd-CreepArghhh Thanks for filing this issue!

This is indeed an unexpected behavior, however I'm no longer using Windows recently so maybe that's why it remains untouched.

I'll have a look into it and hopefully get a fix done real soon. Stay tuned!

rami3l commented 9 months ago

Looks like a regression brought in #537. I guess the ideal precedence would be CLI flags > env vars > config, right? cc @cd-CreepArghhh

00-kat commented 9 months ago

I guess the ideal precedence would be CLI flags > env vars > config, right?

Yeah, that's what I thought would make the most sense.

00-kat commented 9 months ago

By the way, I just installed pacaptr on WSL (Ubuntu) too, and the same problem still exists, so it's probably not a Windows-only issue, unless it's somehow an issue specific to Windows and WSL (which I doubt).

~/.config/pacaptr/pacaptr.toml:

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

# Explicitly set the default package manager
default_pm = "pip"
[I] user@hostname ~> pacaptr -Q
  Running `pip list`
Package                Version
---------------------- -------------
bla bla bla            1.0.0
more useful package    2.0.0
[I] user@hostname ~> pacaptr --using apt -Q
  Running `pip list`
Package                Version
---------------------- -------------
bla bla bla            1.0.0
more useful package    2.0.0
rami3l commented 9 months ago

@cd-CreepArghhh Yes, you're right. I meant to say that this feature is mostly intended for Windows users, but it's true that it could also be used on Linux (but maybe not as often), which is just a possible explanation for why it hasn't been reported till just then.

It'll be a very quick fix, nothing to be worried about on your side!