Add ability to specify updates directory to uptool

This commit is contained in:
Daniel 2019-09-25 12:00:05 +02:00
parent c65d830fc5
commit d0079d692c
3 changed files with 12 additions and 8 deletions

View file

@ -16,11 +16,14 @@ var (
var rootCmd = &cobra.Command{
Use: "uptool",
Short: "helper tool for the update process",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
absPath, err := filepath.Abs(".")
dir := args[0]
absPath, err := filepath.Abs(dir)
if err != nil {
return err
}

View file

@ -14,13 +14,13 @@ func init() {
var scanCmd = &cobra.Command{
Use: "scan",
Short: "Scan the current directory and print the result",
Short: "Scan the specified directory and print the result",
Args: cobra.ExactArgs(1),
RunE: scan,
}
func scan(cmd *cobra.Command, args []string) error {
latest, err := updates.ScanForLatest(".", true)
latest, err := updates.ScanForLatest(updatesStorage.Path, true)
if err != nil {
return err
}

View file

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"github.com/safing/portmaster/updates"
"github.com/spf13/cobra"
@ -14,13 +15,13 @@ func init() {
var updateCmd = &cobra.Command{
Use: "update",
Short: "Update scans the current directory and updates the index and symlink structure",
Short: "Update scans the specified directory and updates the index and symlink structure",
Args: cobra.ExactArgs(1),
RunE: update,
}
func update(cmd *cobra.Command, args []string) error {
latest, err := updates.ScanForLatest(".", true)
latest, err := updates.ScanForLatest(updatesStorage.Path, true)
if err != nil {
return err
}
@ -30,7 +31,7 @@ func update(cmd *cobra.Command, args []string) error {
return err
}
err = ioutil.WriteFile("stable.json", data, 0755)
err = ioutil.WriteFile(filepath.Join(updatesStorage.Path, "stable.json"), data, 0755)
if err != nil {
return err
}