-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathupdate.go
More file actions
135 lines (110 loc) · 4.12 KB
/
update.go
File metadata and controls
135 lines (110 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the cpackget project. */
package commands
import (
"bufio"
"os"
"strings"
errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
"github.com/open-cmsis-pack/cpackget/cmd/installer"
"github.com/open-cmsis-pack/cpackget/cmd/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var updateCmdFlags struct {
// noRequirements skips installing package requirements
noRequirements bool
// packsListFileName is the file name where a list of pack urls is present
packsListFileName string
// skipEula tells whether pack's license should be presented to the user or not for a yay-or-nay acceptance
skipEula bool
// skipTouch does not touch pack.idx after update
skipTouch bool
// Reports encoded progress for files and download when used by other tools
encodedProgress bool
}
var UpdateCmd = &cobra.Command{
Use: "update [<pack> | -f <packs list>]",
Short: "Update Open-CMSIS-Pack packages to latest",
Long: `
Update a pack using the following "<pack>" specification or using packs provided by "-f <packs list>":
$ cpackget update Vendor.Pack
The pack will be updated to the latest version
$ cpackget update
Use this to update all installed packs to the latest version
The pack can be local file or hosted somewhere else on the Internet.
If it's hosted somewhere, cpackget will first download it then extract all pack files into "CMSIS_PACK_ROOT/<vendor>/<packName>/<x.y.z>/"
If "-f" is used, cpackget will call "cpackget update pack" on each URL specified in the <packs list> file.`,
Args: cobra.MinimumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
utils.SetEncodedProgress(updateCmdFlags.encodedProgress)
utils.SetSkipTouch(updateCmdFlags.skipTouch)
createPackRoot = true
err := configureInstaller(cmd, args)
if err != nil {
return err
}
if updateCmdFlags.packsListFileName != "" {
log.Infof("Parsing packs urls via file %v", updateCmdFlags.packsListFileName)
file, err := os.Open(updateCmdFlags.packsListFileName)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
tmpEntry := strings.TrimSpace(scanner.Text())
if len(tmpEntry) == 0 {
continue
}
args = append(args, tmpEntry)
}
if err := scanner.Err(); err != nil {
return err
}
}
var lastErr error
if len(args) == 0 {
if updateCmdFlags.packsListFileName != "" {
return nil // nothing to do
}
installer.UnlockPackRoot()
err := installer.UpdatePack("", !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
if err != nil {
lastErr = err
if !errs.AlreadyLogged(err) {
log.Error(err)
}
}
installer.LockPackRoot()
return lastErr
}
log.Debugf("Specified packs %v", args)
installer.UnlockPackRoot()
for _, packPath := range args {
err := installer.UpdatePack(packPath, !updateCmdFlags.skipEula, updateCmdFlags.noRequirements, viper.GetInt("timeout"))
if err != nil {
lastErr = err
if !errs.AlreadyLogged(err) {
log.Error(err)
}
}
}
installer.LockPackRoot()
return lastErr
},
}
func init() {
UpdateCmd.Flags().BoolVarP(&updateCmdFlags.skipEula, "agree-embedded-license", "a", false, "agrees with the embedded license of the pack")
UpdateCmd.Flags().BoolVarP(&updateCmdFlags.noRequirements, "no-dependencies", "n", false, "do not install package dependencies")
UpdateCmd.Flags().StringVarP(&updateCmdFlags.packsListFileName, "packs-list-filename", "f", "", "specifies a file listing packs urls, one per line")
UpdateCmd.Flags().BoolVar(&updateCmdFlags.skipTouch, "skip-touch", false, "do not touch pack.idx")
UpdateCmd.Flags().BoolVarP(&updateCmdFlags.encodedProgress, "encoded-progress", "E", false, "Reports encoded progress for files and download when used by other tools")
UpdateCmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
// Small workaround to keep the linter happy, not
// really necessary to test this
err := command.Flags().MarkHidden("concurrent-downloads")
log.Debug(err)
command.Parent().HelpFunc()(command, strings)
})
}