feat: cli_toggle
This commit is contained in:
30
brew.py
30
brew.py
@@ -486,6 +486,27 @@ def cli_switch(args: ArgParams) -> None:
|
|||||||
Log.warn('no binary links found. Skipped for new version as well.')
|
Log.warn('no binary links found. Skipped for new version as well.')
|
||||||
|
|
||||||
|
|
||||||
|
def cli_toggle(args: ArgParams) -> None:
|
||||||
|
'''
|
||||||
|
Enable/disable a single package.
|
||||||
|
Can be used to switch between versioned packages (e.g. node <-> node@22).
|
||||||
|
'''
|
||||||
|
pkg = LocalPackage(args.package).assertInstalled()
|
||||||
|
isActive = bool(pkg.activeVersion)
|
||||||
|
baseName = pkg.name.split('@')[0]
|
||||||
|
allVersions = [x for x in Cellar.infoAll()
|
||||||
|
if x.name == baseName or x.name.startswith(baseName + '@')]
|
||||||
|
|
||||||
|
for prev in allVersions:
|
||||||
|
prev.unlink()
|
||||||
|
|
||||||
|
if isActive:
|
||||||
|
Log.info('==> disabled', pkg.name)
|
||||||
|
else:
|
||||||
|
pkg.anyVersion().link()
|
||||||
|
Log.info('==> enabled', pkg.name, pkg.activeVersion)
|
||||||
|
|
||||||
|
|
||||||
# https://docs.brew.sh/Manpage#pin-installed_formula-
|
# https://docs.brew.sh/Manpage#pin-installed_formula-
|
||||||
def cli_pin(args: ArgParams) -> None:
|
def cli_pin(args: ArgParams) -> None:
|
||||||
''' Prevent specified packages from being upgraded. '''
|
''' Prevent specified packages from being upgraded. '''
|
||||||
@@ -726,6 +747,10 @@ def parseArgs() -> ArgParams:
|
|||||||
cmd.arg('package', help='Brew package name')
|
cmd.arg('package', help='Brew package name')
|
||||||
cmd.arg('version', nargs='?', help='Package version') # convenience omit
|
cmd.arg('version', nargs='?', help='Package version') # convenience omit
|
||||||
|
|
||||||
|
# toggle
|
||||||
|
cmd = cli.subcommand('toggle', cli_toggle)
|
||||||
|
cmd.arg('package', help='Brew package name')
|
||||||
|
|
||||||
# pin
|
# pin
|
||||||
cmd = cli.subcommand('pin', cli_pin)
|
cmd = cli.subcommand('pin', cli_pin)
|
||||||
cmd.arg('packages', nargs='+', help='Brew package name')
|
cmd.arg('packages', nargs='+', help='Brew package name')
|
||||||
@@ -1137,6 +1162,11 @@ class LocalPackage:
|
|||||||
''' Create new `LocalPackageVersion` instance '''
|
''' Create new `LocalPackageVersion` instance '''
|
||||||
return LocalPackageVersion(self, version)
|
return LocalPackageVersion(self, version)
|
||||||
|
|
||||||
|
def anyVersion(self) -> 'LocalPackageVersion':
|
||||||
|
''' Return any of the installed versions (should be latest) '''
|
||||||
|
assert self.installed, 'Only installed packages can call anyVersion()'
|
||||||
|
return self.version(self.allVersions[-1]) # alphanumeric sort, latest
|
||||||
|
|
||||||
def checkUpdate(self, *, force: bool = False) -> None:
|
def checkUpdate(self, *, force: bool = False) -> None:
|
||||||
''' Print whether package is up-to-date or needs upgrade '''
|
''' Print whether package is up-to-date or needs upgrade '''
|
||||||
if self.installed:
|
if self.installed:
|
||||||
|
|||||||
Reference in New Issue
Block a user