From 1ab44f4b2a2dc38cde8908ce18834ce13d73db58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 18 Jun 2015 19:47:07 +0200 Subject: [PATCH] Move common functions to files that make more sense --- cmd/fdroidcl/devices.go | 14 ++++++++++++++ cmd/fdroidcl/installed.go | 14 -------------- cmd/fdroidcl/search.go | 23 ----------------------- cmd/fdroidcl/update.go | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/cmd/fdroidcl/devices.go b/cmd/fdroidcl/devices.go index 853c0d5..231fdd7 100644 --- a/cmd/fdroidcl/devices.go +++ b/cmd/fdroidcl/devices.go @@ -39,3 +39,17 @@ func startAdbIfNeeded() { log.Fatalf("Could not start ADB server: %v", err) } } + +func oneDevice() adb.Device { + devices, err := adb.Devices() + if err != nil { + log.Fatalf("Could not get devices: %v", err) + } + if len(devices) == 0 { + log.Fatalf("No devices found") + } + if len(devices) > 1 { + log.Fatalf("Too many devices found") + } + return devices[0] +} diff --git a/cmd/fdroidcl/installed.go b/cmd/fdroidcl/installed.go index 5622d36..3e8db3c 100644 --- a/cmd/fdroidcl/installed.go +++ b/cmd/fdroidcl/installed.go @@ -28,20 +28,6 @@ func runInstalled(args []string) { printApps(apps) } -func oneDevice() adb.Device { - devices, err := adb.Devices() - if err != nil { - log.Fatalf("Could not get devices: %v", err) - } - if len(devices) == 0 { - log.Fatalf("No devices found") - } - if len(devices) > 1 { - log.Fatalf("Too many devices found") - } - return devices[0] -} - func mustInstalled(device adb.Device) []string { installed, err := device.Installed() if err != nil { diff --git a/cmd/fdroidcl/search.go b/cmd/fdroidcl/search.go index bc4f04d..953a505 100644 --- a/cmd/fdroidcl/search.go +++ b/cmd/fdroidcl/search.go @@ -5,8 +5,6 @@ package main import ( "fmt" - "log" - "os" "regexp" "strings" @@ -38,27 +36,6 @@ func runSearch(args []string) { } } -func mustLoadIndex() *fdroidcl.Index { - p := indexPath(repoName) - f, err := os.Open(p) - if err != nil { - log.Fatalf("Could not open index file: %v", err) - } - stat, err := f.Stat() - if err != nil { - log.Fatalf("Could not stat index file: %v", err) - } - //pubkey, err := hex.DecodeString(repoPubkey) - //if err != nil { - // log.Fatalf("Could not decode public key: %v", err) - //} - index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil) - if err != nil { - log.Fatalf("Could not load index: %v", err) - } - return index -} - func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App { regexes := make([]*regexp.Regexp, len(terms)) for i, term := range terms { diff --git a/cmd/fdroidcl/update.go b/cmd/fdroidcl/update.go index a85ce2a..5ff4e14 100644 --- a/cmd/fdroidcl/update.go +++ b/cmd/fdroidcl/update.go @@ -13,6 +13,7 @@ import ( "path/filepath" "github.com/mvdan/appdir" + "github.com/mvdan/fdroidcl" ) var cmdUpdate = &Command{ @@ -97,3 +98,24 @@ func appSubdir(appdir string) string { } return p } + +func mustLoadIndex() *fdroidcl.Index { + p := indexPath(repoName) + f, err := os.Open(p) + if err != nil { + log.Fatalf("Could not open index file: %v", err) + } + stat, err := f.Stat() + if err != nil { + log.Fatalf("Could not stat index file: %v", err) + } + //pubkey, err := hex.DecodeString(repoPubkey) + //if err != nil { + // log.Fatalf("Could not decode public key: %v", err) + //} + index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil) + if err != nil { + log.Fatalf("Could not load index: %v", err) + } + return index +}