Browse Source

install: add exclude option for upgrading

related issue: #53
pull/70/head
Linus789 3 years ago
parent
commit
6811e291cb
  1. 31
      install.go
  2. 3
      testdata/scripts/cmds.txt

31
install.go

@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os"
"strings"
"mvdan.cc/fdroidcl/adb"
"mvdan.cc/fdroidcl/fdroid"
@ -26,10 +27,11 @@ list of apps to install from standard input, like:
}
var (
installUpdates = cmdInstall.Fset.Bool("u", false, "Upgrade all installed apps")
installDryRun = cmdInstall.Fset.Bool("n", false, "Only print the operations that would be done")
installSkipError = cmdInstall.Fset.Bool("s", false, "Skip to the next application if a download or install error occurs")
installUser = cmdInstall.Fset.String("user", "", "Only install for specified user")
installUpdates = cmdInstall.Fset.Bool("u", false, "Upgrade all installed apps")
installDryRun = cmdInstall.Fset.Bool("n", false, "Only print the operations that would be done")
installUpdatesExclude = cmdInstall.Fset.String("e", "", "Exclude apps from upgrading (comma-separated list)")
installSkipError = cmdInstall.Fset.Bool("s", false, "Skip to the next application if a download or install error occurs")
installUser = cmdInstall.Fset.String("user", "", "Only install for specified user")
)
func init() {
@ -40,6 +42,9 @@ func runInstall(args []string) error {
if *installUpdates && len(args) > 0 {
return fmt.Errorf("-u can only be used without arguments")
}
if *installUpdatesExclude != "" && !*installUpdates {
return fmt.Errorf("-e can only be used for upgrading (i.e. -u)")
}
device, err := oneDevice()
if err != nil {
return err
@ -55,6 +60,24 @@ func runInstall(args []string) error {
return err
}
apps = filterAppsUpdates(apps, inst, device)
if *installUpdatesExclude != "" {
excludeApps := strings.Split(*installUpdatesExclude, ",")
installApps := make([]fdroid.App, 0)
for _, app := range apps {
shouldExclude := false
for _, exclude := range excludeApps {
if app.PackageName == exclude {
shouldExclude = true
break
}
}
if shouldExclude {
continue
}
installApps = append(installApps, app)
}
apps = installApps
}
if len(apps) == 0 {
fmt.Fprintln(os.Stderr, "All apps up to date.")
}

3
testdata/scripts/cmds.txt vendored

@ -30,6 +30,9 @@ stderr 'When given no arguments'
! fdroidcl install -u some.app
stderr 'without arguments'
! fdroidcl install -e com.fsck.k9,org.videolan.vlc
stderr '-e can only be used for upgrading'
! fdroidcl clean a b
stderr 'wrong amount of arguments'

Loading…
Cancel
Save