Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9596a7c

Browse files
committedAug 26, 2021
Add periodical check to notify users of new CLI releases
1 parent 4010bcd commit 9596a7c

File tree

15 files changed

+203
-41
lines changed

15 files changed

+203
-41
lines changed
 

‎arduino/discovery/discovery_client/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
141141
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
142142
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
143143
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
144+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
145+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
144146
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
145147
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
146148
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=

‎cli/cli.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ import (
4646
"github.com/arduino/arduino-cli/i18n"
4747
"github.com/arduino/arduino-cli/inventory"
4848
"github.com/mattn/go-colorable"
49+
"github.com/mgutz/ansi"
4950
"github.com/rifflock/lfshook"
5051
"github.com/sirupsen/logrus"
5152
"github.com/spf13/cobra"
53+
semver "go.bug.st/relaxed-semver"
5254
)
5355

5456
var (
55-
verbose bool
56-
outputFormat string
57-
configFile string
57+
verbose bool
58+
outputFormat string
59+
configFile string
60+
updaterMessageChan chan *semver.Version = make(chan *semver.Version)
5861
)
5962

6063
// NewCommand creates a new ArduinoCli command root
@@ -63,11 +66,12 @@ func NewCommand() *cobra.Command {
6366

6467
// ArduinoCli is the root command
6568
arduinoCli := &cobra.Command{
66-
Use: "arduino-cli",
67-
Short: tr("Arduino CLI."),
68-
Long: tr("Arduino Command Line Interface (arduino-cli)."),
69-
Example: fmt.Sprintf(" %s <%s> [%s...]", os.Args[0], tr("command"), tr("flags")),
70-
PersistentPreRun: preRun,
69+
Use: "arduino-cli",
70+
Short: tr("Arduino CLI."),
71+
Long: tr("Arduino Command Line Interface (arduino-cli)."),
72+
Example: fmt.Sprintf(" %s <%s> [%s...]", os.Args[0], tr("command"), tr("flags")),
73+
PersistentPreRun: preRun,
74+
PersistentPostRun: postRun,
7175
}
7276

7377
arduinoCli.SetUsageTemplate(usageTemplate)
@@ -142,6 +146,16 @@ func preRun(cmd *cobra.Command, args []string) {
142146
os.Exit(errorcodes.ErrBadArgument)
143147
}
144148

149+
updaterMessageChan = make(chan *semver.Version)
150+
go func() {
151+
// Starts checking for updates
152+
currentVersion, err := semver.Parse(globals.VersionInfo.VersionString)
153+
if err != nil {
154+
updaterMessageChan <- nil
155+
}
156+
updaterMessageChan <- checkForUpdate(currentVersion)
157+
}()
158+
145159
//
146160
// Prepare logging
147161
//
@@ -226,3 +240,17 @@ func preRun(cmd *cobra.Command, args []string) {
226240
})
227241
}
228242
}
243+
244+
func postRun(cmd *cobra.Command, args []string) {
245+
latestVersion := <-updaterMessageChan
246+
if latestVersion != nil {
247+
// Notify the user a new version is available
248+
feedback.Errorf("\n\n%s %s → %s",
249+
ansi.Color("A new release of arduino-cli is available:", "yellow"),
250+
ansi.Color(globals.VersionInfo.VersionString, "cyan"),
251+
ansi.Color(latestVersion.String(), "cyan"))
252+
feedback.Errorf("%s%s",
253+
ansi.Color("https://github.com/arduino/arduino-cli/releases/tag/", "yellow"),
254+
ansi.Color(latestVersion.String(), "yellow"))
255+
}
256+
}

‎cli/config/validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var validMap = map[string]reflect.Kind{
3535
"metrics.enabled": reflect.Bool,
3636
"network.proxy": reflect.String,
3737
"network.user_agent_ext": reflect.String,
38+
"updater.disable_notification": reflect.Bool,
3839
}
3940

4041
func typeOf(key string) (reflect.Kind, error) {

‎cli/updater.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package cli
17+
18+
import (
19+
"os"
20+
"strings"
21+
"time"
22+
23+
"github.com/arduino/arduino-cli/configuration"
24+
"github.com/arduino/arduino-cli/httpclient"
25+
"github.com/arduino/arduino-cli/inventory"
26+
semver "go.bug.st/relaxed-semver"
27+
)
28+
29+
// checkForUpdate return the latest available version if greater than
30+
// the one running, nil in all other cases
31+
func checkForUpdate(currentVersion *semver.Version) *semver.Version {
32+
if !shouldCheckForUpdate(currentVersion) {
33+
return nil
34+
}
35+
36+
defer func() {
37+
// Always save the last time we checked for updates at the end
38+
inventory.Store.Set("updater.last_check_time", time.Now())
39+
inventory.WriteStore()
40+
}()
41+
42+
latestVersion, err := semver.Parse(getLatestRelease())
43+
if err != nil {
44+
return nil
45+
}
46+
47+
if currentVersion.GreaterThanOrEqual(latestVersion) {
48+
// Current version is already good enough
49+
return nil
50+
}
51+
52+
return latestVersion
53+
}
54+
55+
// shouldCheckForUpdate return true if it actually makes sense to check for new updates,
56+
// false in all other cases.
57+
func shouldCheckForUpdate(currentVersion *semver.Version) bool {
58+
if strings.Contains(currentVersion.String(), "git") {
59+
// This is a dev build, no need to check for updates
60+
return false
61+
}
62+
63+
if configuration.Settings.GetBool("updater.disable_notification") {
64+
// Don't check if the user disable the notification
65+
return false
66+
}
67+
68+
if inventory.Store.IsSet("updater.last_check_time") && time.Since(inventory.Store.GetTime("updater.last_check_time")).Hours() < 24 {
69+
// Checked less than 24 hours ago, let's wait
70+
return false
71+
}
72+
73+
// Don't check when running on CI or on non interactive consoles
74+
return !isCI() && configuration.IsInteractive && configuration.HasConsole
75+
}
76+
77+
// based on https://github.com/watson/ci-info/blob/HEAD/index.js
78+
func isCI() bool {
79+
return os.Getenv("CI") != "" || // GitHub Actions, Travis CI, CircleCI, Cirrus CI, GitLab CI, AppVeyor, CodeShip, dsari
80+
os.Getenv("BUILD_NUMBER") != "" || // Jenkins, TeamCity
81+
os.Getenv("RUN_ID") != "" // TaskCluster, dsari
82+
}
83+
84+
// getLatestRelease queries the official Arduino download server for the latest release,
85+
// if there are no errors or issues a version string is returned, in all other case an empty string.
86+
func getLatestRelease() string {
87+
client, err := httpclient.New()
88+
if err != nil {
89+
return ""
90+
}
91+
92+
// We just use this URL to check if there's a new release available and
93+
// never show it to the user, so it's fine to use the Linux one for all OSs.
94+
URL := "https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz"
95+
res, err := client.Get(URL)
96+
if err != nil {
97+
// Yes, we ignore it
98+
return ""
99+
}
100+
101+
// Get redirected URL
102+
location := res.Request.URL.String()
103+
104+
// The location header points to the the latest release of the CLI, it's supposed to be formatted like this:
105+
// https://downloads.arduino.cc/arduino-cli/arduino-cli_0.18.3_Linux_64bit.tar.gz
106+
// so we split it to get the version, if there are not enough splits something must have gone wrong.
107+
split := strings.Split(location, "_")
108+
if len(split) < 2 {
109+
return ""
110+
}
111+
112+
return split[1]
113+
}

‎client_example/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
129129
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
130130
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
131131
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
132+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
132133
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
133134
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
134135
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

‎commands/daemon/term_example/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
129129
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
130130
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
131131
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
132+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
132133
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
133134
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
134135
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

‎configuration/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func SetDefaults(settings *viper.Viper) {
4949
settings.SetDefault("metrics.enabled", true)
5050
settings.SetDefault("metrics.addr", ":9090")
5151

52+
// updater settings
53+
settings.SetDefault("updater.disable_notification", false)
54+
5255
// Bind env vars
5356
settings.SetEnvPrefix("ARDUINO")
5457
settings.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

‎docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- `sketch` - configuration options relating to [Arduino sketches][sketch specification].
2525
- `always_export_binaries` - set to `true` to make [`arduino-cli compile`][arduino-cli compile] always save binaries
2626
to the sketch folder. This is the equivalent of using the [`--export-binaries`][arduino-cli compile options] flag.
27+
- `updater` - configuration options related to Arduino CLI updates
28+
- `disable_notification` - set to `true` to disable notifications of new Arduino CLI releases, defaults to `false`
2729

2830
## Configuration methods
2931

‎docs/installation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ as a parameter like this:
4040
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s 0.9.0
4141
```
4242

43+
The Arduino CLI verifies every 24 hours if there are new releases, if you don't like this behaviour you can disable it
44+
by setting the `updater.disable_notification` config or the env var `ARDUINO_UPDATER_DISABLE_NOTIFICATION` to `true`.
45+
4346
### Download
4447

4548
Pre-built binaries for all the supported platforms are available for download from the links below.

‎docsgen/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
171171
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
172172
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
173173
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
174+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
175+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
174176
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
175177
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
176178
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=

‎go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/mattn/go-colorable v0.1.2
2525
github.com/mattn/go-isatty v0.0.8
2626
github.com/mattn/go-runewidth v0.0.9 // indirect
27+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
2728
github.com/miekg/dns v1.1.43 // indirect
2829
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect
2930
github.com/pkg/errors v0.9.1

‎go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
172172
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851/go.mod h1:EsbsAEUEs15qC1cosAwxgCWV0Qhd8TmkxnA9Kw1Vhl4=
173173
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
174174
github.com/mdlayher/taskstats v0.0.0-20190313225729-7cbba52ee072/go.mod h1:sGdS7A6CAETR53zkdjGkgoFlh1vSm7MtX+i8XfEsTMA=
175+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
176+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
175177
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
176178
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
177179
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=

‎i18n/data/en.po

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ msgstr "Archiving built core (caching) in: {0}"
160160
msgid "Arduino CLI sketch commands."
161161
msgstr "Arduino CLI sketch commands."
162162

163-
#: cli/cli.go:67
163+
#: cli/cli.go:70
164164
msgid "Arduino CLI."
165165
msgstr "Arduino CLI."
166166

167-
#: cli/cli.go:68
167+
#: cli/cli.go:71
168168
msgid "Arduino Command Line Interface (arduino-cli)."
169169
msgstr "Arduino Command Line Interface (arduino-cli)."
170170

@@ -327,7 +327,7 @@ msgstr "Checksum:"
327327
msgid "Clean caches."
328328
msgstr "Clean caches."
329329

330-
#: cli/cli.go:106
330+
#: cli/cli.go:110
331331
msgid "Comma-separated list of additional URLs for the Boards Manager."
332332
msgstr "Comma-separated list of additional URLs for the Boards Manager."
333333

@@ -986,7 +986,7 @@ msgstr "Installs one or more specified libraries into the system."
986986
msgid "Internal error in cache"
987987
msgstr "Internal error in cache"
988988

989-
#: cli/cli.go:224
989+
#: cli/cli.go:238
990990
msgid "Invalid Call : should show Help, but it is available only in TEXT mode."
991991
msgstr "Invalid Call : should show Help, but it is available only in TEXT mode."
992992

@@ -1023,11 +1023,11 @@ msgstr "Invalid item %s"
10231023
msgid "Invalid network.proxy '%[1]s': %[2]s"
10241024
msgstr "Invalid network.proxy '%[1]s': %[2]s"
10251025

1026-
#: cli/cli.go:185
1026+
#: cli/cli.go:199
10271027
msgid "Invalid option for --log-level: %s"
10281028
msgstr "Invalid option for --log-level: %s"
10291029

1030-
#: cli/cli.go:202
1030+
#: cli/cli.go:216
10311031
msgid "Invalid output format: %s"
10321032
msgstr "Invalid output format: %s"
10331033

@@ -1170,7 +1170,7 @@ msgstr "Maintainer: %s"
11701170
msgid "Max time to wait for port discovery, e.g.: 30s, 1m"
11711171
msgstr "Max time to wait for port discovery, e.g.: 30s, 1m"
11721172

1173-
#: cli/cli.go:101
1173+
#: cli/cli.go:105
11741174
msgid "Messages with this level and above will be logged. Valid levels are: %s, %s, %s, %s, %s, %s, %s"
11751175
msgstr "Messages with this level and above will be logged. Valid levels are: %s, %s, %s, %s, %s, %s, %s"
11761176

@@ -1344,7 +1344,7 @@ msgstr "Package website:"
13441344
msgid "Paragraph: %s"
13451345
msgstr "Paragraph: %s"
13461346

1347-
#: cli/cli.go:102
1347+
#: cli/cli.go:106
13481348
msgid "Path to the file where logs will be written."
13491349
msgstr "Path to the file where logs will be written."
13501350

@@ -1418,7 +1418,7 @@ msgstr "Print details about a board."
14181418
msgid "Print preprocessed code to stdout instead of compiling."
14191419
msgstr "Print preprocessed code to stdout instead of compiling."
14201420

1421-
#: cli/cli.go:100
1421+
#: cli/cli.go:104
14221422
msgid "Print the logs on the standard output."
14231423
msgstr "Print the logs on the standard output."
14241424

@@ -1531,7 +1531,7 @@ msgid "Setting build path to {0}"
15311531
msgstr "Setting build path to {0}"
15321532

15331533
#: cli/config/delete.go:57
1534-
#: cli/config/validate.go:43
1534+
#: cli/config/validate.go:44
15351535
msgid "Settings key doesn't exist"
15361536
msgstr "Settings key doesn't exist"
15371537

@@ -1685,7 +1685,7 @@ msgstr "The connected devices search timeout, raise it if your board doesn't sho
16851685
msgid "The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"
16861686
msgstr "The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"
16871687

1688-
#: cli/cli.go:105
1688+
#: cli/cli.go:109
16891689
msgid "The custom config file (if not specified the default will be used)."
16901690
msgstr "The custom config file (if not specified the default will be used)."
16911691

@@ -1705,11 +1705,11 @@ msgid "The key '%[1]v' is not a list of items, can't remove from it.\n"
17051705
msgstr "The key '%[1]v' is not a list of items, can't remove from it.\n"
17061706
"Maybe use '%[2]s'?"
17071707

1708-
#: cli/cli.go:103
1708+
#: cli/cli.go:107
17091709
msgid "The output format for the logs, can be {%s|%s}."
17101710
msgstr "The output format for the logs, can be {%s|%s}."
17111711

1712-
#: cli/cli.go:104
1712+
#: cli/cli.go:108
17131713
msgid "The output format, can be {%s|%s}."
17141714
msgstr "The output format, can be {%s|%s}."
17151715

@@ -1791,7 +1791,7 @@ msgstr "Unable to get Local App Data Folder: %v"
17911791
msgid "Unable to get user home dir: %v"
17921792
msgstr "Unable to get user home dir: %v"
17931793

1794-
#: cli/cli.go:171
1794+
#: cli/cli.go:185
17951795
msgid "Unable to open file for logging: %s"
17961796
msgstr "Unable to open file for logging: %s"
17971797

@@ -2186,7 +2186,7 @@ msgstr "chip erase error: %s"
21862186
msgid "cleaning build path"
21872187
msgstr "cleaning build path"
21882188

2189-
#: cli/cli.go:69
2189+
#: cli/cli.go:72
21902190
msgid "command"
21912191
msgstr "command"
21922192

@@ -2440,7 +2440,7 @@ msgstr "finding platform dependencies: %s"
24402440
msgid "first message must contain monitor configuration, not data"
24412441
msgstr "first message must contain monitor configuration, not data"
24422442

2443-
#: cli/cli.go:69
2443+
#: cli/cli.go:72
24442444
msgid "flags"
24452445
msgstr "flags"
24462446

@@ -2471,11 +2471,11 @@ msgstr "for the specific version."
24712471
msgid "gathering library headers: %w"
24722472
msgstr "gathering library headers: %w"
24732473

2474-
#: inventory/inventory.go:67
2474+
#: inventory/inventory.go:68
24752475
msgid "generating installation.id: %w"
24762476
msgstr "generating installation.id: %w"
24772477

2478-
#: inventory/inventory.go:73
2478+
#: inventory/inventory.go:74
24792479
msgid "generating installation.secret: %w"
24802480
msgstr "generating installation.secret: %w"
24812481

@@ -2674,11 +2674,11 @@ msgstr "invalid option '%s'"
26742674
msgid "invalid package index in %[1]s: %[2]s"
26752675
msgstr "invalid package index in %[1]s: %[2]s"
26762676

2677-
#: inventory/inventory.go:85
2677+
#: inventory/inventory.go:88
26782678
msgid "invalid path creating config dir: %[1]s error: %[2]w"
26792679
msgstr "invalid path creating config dir: %[1]s error: %[2]w"
26802680

2681-
#: inventory/inventory.go:91
2681+
#: inventory/inventory.go:94
26822682
msgid "invalid path writing inventory file: %[1]s error: %[2]w"
26832683
msgstr "invalid path writing inventory file: %[1]s error: %[2]w"
26842684

@@ -3079,7 +3079,7 @@ msgstr "reading file %[1]s: %[2]s"
30793079
msgid "reading files: %v"
30803080
msgstr "reading files: %v"
30813081

3082-
#: inventory/inventory.go:57
3082+
#: inventory/inventory.go:58
30833083
msgid "reading inventory file: %w"
30843084
msgstr "reading inventory file: %w"
30853085

‎i18n/rice-box.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎inventory/inventory.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ var (
3232
// Type is the inventory file type
3333
Type = "yaml"
3434
// Name is the inventory file Name with Type as extension
35-
Name = "inventory" + "." + Type
36-
tr = i18n.Tr
35+
Name = "inventory" + "." + Type
36+
tr = i18n.Tr
37+
configFilePath string
3738
)
3839

3940
// Init configures the Read Only config storage
4041
func Init(configPath string) error {
41-
configFilePath := filepath.Join(configPath, Name)
42+
configFilePath = filepath.Join(configPath, Name)
4243
Store.SetConfigName(Name)
4344
Store.SetConfigType(Type)
4445
Store.AddConfigPath(configPath)
@@ -50,7 +51,7 @@ func Init(configPath string) error {
5051
if err := generateInstallationData(); err != nil {
5152
return err
5253
}
53-
if err := writeStore(configFilePath); err != nil {
54+
if err := WriteStore(); err != nil {
5455
return err
5556
}
5657
} else {
@@ -76,7 +77,9 @@ func generateInstallationData() error {
7677
return nil
7778
}
7879

79-
func writeStore(configFilePath string) error {
80+
// WriteStore writes the current information from Store to configFilePath.
81+
// Returns err if it fails.
82+
func WriteStore() error {
8083
configPath := filepath.Dir(configFilePath)
8184

8285
// Create config dir if not present,

0 commit comments

Comments
 (0)
Please sign in to comment.