diff --git a/README.md b/README.md index dd8cfae1..68daf358 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,7 @@ Enabled by default only on specific platforms: * `apt_get` – installs app from apt if it not installed (requires `python-commandnotfound` / `python3-commandnotfound`); * `apt_get_search` – changes trying to search using `apt-get` with searching using `apt-cache`; * `apt_invalid_operation` – fixes invalid `apt` and `apt-get` calls, like `apt-get isntall vim`; +* `apt_list_upgradable` – helps you run `apt list --upgradable` after `apt update`; * `brew_cask_dependency` – installs cask dependencies; * `brew_install` – fixes formula name for `brew install`; * `brew_link` – adds `--overwrite --dry-run` if linking fails; diff --git a/tests/rules/test_apt_list_upgradable.py b/tests/rules/test_apt_list_upgradable.py new file mode 100644 index 00000000..567b8558 --- /dev/null +++ b/tests/rules/test_apt_list_upgradable.py @@ -0,0 +1,72 @@ +import pytest +from thefuck.rules.apt_list_upgradable import get_new_command, match +from thefuck.types import Command + +match_output = ''' +Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease +Hit:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease +Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB] +Hit:4 http://security.ubuntu.com/ubuntu zesty-security InRelease +Hit:5 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease +Hit:6 https://download.docker.com/linux/ubuntu zesty InRelease +Hit:7 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease +Fetched 89.2 kB in 0s (122 kB/s) +Reading package lists... Done +Building dependency tree +Reading state information... Done +8 packages can be upgraded. Run 'apt list --upgradable' to see them. +''' + +no_match_output = ''' +Hit:1 http://us.archive.ubuntu.com/ubuntu zesty InRelease +Get:2 http://us.archive.ubuntu.com/ubuntu zesty-updates InRelease [89.2 kB] +Get:3 http://us.archive.ubuntu.com/ubuntu zesty-backports InRelease [89.2 kB] +Get:4 http://security.ubuntu.com/ubuntu zesty-security InRelease [89.2 kB] +Hit:5 https://cli-assets.heroku.com/branches/stable/apt ./ InRelease +Hit:6 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu zesty InRelease +Hit:7 https://download.docker.com/linux/ubuntu zesty InRelease +Get:8 http://us.archive.ubuntu.com/ubuntu zesty-updates/main i386 Packages [232 kB] +Get:9 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 Packages [235 kB] +Get:10 http://us.archive.ubuntu.com/ubuntu zesty-updates/main amd64 DEP-11 Metadata [55.2 kB] +Get:11 http://us.archive.ubuntu.com/ubuntu zesty-updates/main DEP-11 64x64 Icons [32.3 kB] +Get:12 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 Packages [156 kB] +Get:13 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe i386 Packages [156 kB] +Get:14 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe amd64 DEP-11 Metadata [175 kB] +Get:15 http://us.archive.ubuntu.com/ubuntu zesty-updates/universe DEP-11 64x64 Icons [253 kB] +Get:16 http://us.archive.ubuntu.com/ubuntu zesty-updates/multiverse amd64 DEP-11 Metadata [5,840 B] +Get:17 http://us.archive.ubuntu.com/ubuntu zesty-backports/universe amd64 DEP-11 Metadata [4,588 B] +Get:18 http://security.ubuntu.com/ubuntu zesty-security/main amd64 DEP-11 Metadata [12.7 kB] +Get:19 http://security.ubuntu.com/ubuntu zesty-security/main DEP-11 64x64 Icons [17.6 kB] +Get:20 http://security.ubuntu.com/ubuntu zesty-security/universe amd64 DEP-11 Metadata [21.6 kB] +Get:21 http://security.ubuntu.com/ubuntu zesty-security/universe DEP-11 64x64 Icons [47.7 kB] +Get:22 http://security.ubuntu.com/ubuntu zesty-security/multiverse amd64 DEP-11 Metadata [208 B] +Fetched 1,673 kB in 0s (1,716 kB/s) +Reading package lists... Done +Building dependency tree +Reading state information... Done +All packages are up to date. +''' + + +def test_match(): + assert match(Command('sudo apt update', match_output)) + + +@pytest.mark.parametrize('command', [ + Command('apt-cache search foo', ''), + Command('aptitude search foo', ''), + Command('apt search foo', ''), + Command('apt-get install foo', ''), + Command('apt-get source foo', ''), + Command('apt-get clean', ''), + Command('apt-get remove', ''), + Command('apt-get update', ''), + Command('sudo apt update', no_match_output) +]) +def test_not_match(command): + assert not match(command) + + +def test_get_new_command(): + new_command = get_new_command(Command('sudo apt update', match_output)) + assert new_command == 'apt list --upgradable' diff --git a/thefuck/rules/apt_list_upgradable.py b/thefuck/rules/apt_list_upgradable.py new file mode 100644 index 00000000..767b201c --- /dev/null +++ b/thefuck/rules/apt_list_upgradable.py @@ -0,0 +1,15 @@ +from thefuck.specific.apt import apt_available +from thefuck.specific.sudo import sudo_support +from thefuck.utils import for_app + +enabled_by_default = apt_available + + +@sudo_support +@for_app('apt') +def match(command): + return "Run 'apt list --upgradable' to see them." in command.output + + +def get_new_command(command): + return 'apt list --upgradable'