Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt_invalid_operation Issue with @for_app #860

Closed
chrisdepas opened this issue Dec 7, 2018 · 2 comments
Closed

apt_invalid_operation Issue with @for_app #860

chrisdepas opened this issue Dec 7, 2018 · 2 comments

Comments

@chrisdepas
Copy link
Contributor

Issue

sudo apt install commands aren't fixed correctly. The package I wanted to install is discarded, and something else is substitutued in it's place.

It appears to be skipping apt_invalid_operation, and pulling some random line from history to suggest instead. The suggestions are all commands I've executed in the past.

This only seems to occur when using sudo or multiple typos are present.


Example output

Note that the commands are what I actually executed

Command Suggestion
at instal thing sudo apt install libpango
sudo apt instal instal sudo apt install wine-stable
sudo apt instal very_long_package_name sudo apt install pwgen

Output of thefuck --version

The Fuck 3.28 using Python 3.6.7 and Bash 4.4.19(1)-release


System

Ubuntu Server 18.04, Linux 4.15.0-42-generic

bash


Reproducing

  1. ~$ sudo apt instal i7z
  2. ~$ fuck

Output

~$ sudo apt instal i7z
E: Invalid operation instal
~$ fuck
sudo apt install file [enter/↑/↓/ctrl+c]

thefuck Debug Output

https://gist.github.com/chrisdepas/5efe6dcb5c8990f2dff39413ac15575d


Other Useful Information

The issue seems to be that apt_invalid_operation fails it's match. If I disable all other packages (using rules=['apt_invalid_operation']), then the output is always 'No fucks given'.

Further testing with a copy of apt_invalid_operation installed as a custom rule showed that removing the for_app decorator fixed the issue. (specifically, the line @for_app('apt') on the match function).

I.e. with this config

rules = ["apt_invalid_operation"]

I get this output:

~$ sudo apt instal i3bar
E: Invalid operation instal
~$ fuck
..snip..
DEBUG: Trying rule: apt_invalid_operation; took: 0:00:00.000079
No fucks given

However, testing a copy of apt_invalid_operation as a custom rule with for_app removed

rules = ["new_apt_invalid_op"]

Gives this output

~$ sudo apt instal i3bar
E: Invalid operation instal
~$ fuck
..snip..
DEBUG: Trying rule: new_apt_invalid_op; took: 0:00:00.000024
sudo apt install i3bar [enter/↑/↓/ctrl+c]
@chrisdepas
Copy link
Contributor Author

chrisdepas commented Dec 8, 2018

Okay, I found the problem. This was caused by the order of for_app and sudo_support.

The ordering in apt_invalid_operation (and also dnf_no_such_command) was wrong, and meant that the input to for_app contained a sudo prefix, and would fail.

I've made a PR, which is here

@chrisdepas
Copy link
Contributor Author

Fix was merged, closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant