Skip to content

Commit 4f3552f

Browse files
authored
Merge pull request #2 from arduino/add_version
Added `version` command
2 parents baed5fc + a3e391d commit 4f3552f

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

cli.go

+25
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/arduino/go-paths-helper"
2525
"github.com/spf13/cobra"
26+
"gopkg.in/yaml.v3"
2627
)
2728

2829
// RunPlugin runs the given plugin
@@ -100,13 +101,22 @@ func RunPlugin(plugin Plugin) {
100101
}
101102
certCmd.AddCommand(certFlashCmd)
102103

104+
versionCmd := &cobra.Command{
105+
Use: "version",
106+
Short: "Return informations about this fw-updater plugin",
107+
Run: func(cmd *cobra.Command, args []string) {
108+
printInfo(info)
109+
},
110+
}
111+
103112
appName := filepath.Base(os.Args[0])
104113
cli := &cobra.Command{
105114
Use: appName,
106115
Short: info.Name + " - This is an Arduino Firmware Uploader plugin.",
107116
}
108117
cli.AddCommand(firmwareCmd)
109118
cli.AddCommand(certCmd)
119+
cli.AddCommand(versionCmd)
110120
cli.PersistentFlags().StringVarP(&portAddress, "address", "p", "", "Port address")
111121

112122
if err := cli.Execute(); err != nil {
@@ -118,3 +128,18 @@ func fatal(msg string, exitcode int) {
118128
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
119129
os.Exit(exitcode)
120130
}
131+
132+
func printInfo(info *PluginInfo) {
133+
type infoResult struct {
134+
PluginInfo *PluginInfo `yaml:"plugin_info"`
135+
PluginAPIVersion int `yaml:"plugin_api_version"`
136+
}
137+
data, err := yaml.Marshal(&infoResult{
138+
PluginAPIVersion: 1,
139+
PluginInfo: info,
140+
})
141+
if err != nil {
142+
fatal(err.Error(), 3)
143+
}
144+
fmt.Println(string(data))
145+
}

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ go 1.20
55
require (
66
github.com/arduino/go-paths-helper v1.9.1
77
github.com/spf13/cobra v1.7.0
8-
go.bug.st/relaxed-semver v0.10.2
8+
go.bug.st/relaxed-semver v0.11.0
9+
gopkg.in/yaml.v3 v3.0.1
910
)
1011

1112
require (

go.sum

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
1717
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1818
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1919
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
20-
go.bug.st/relaxed-semver v0.10.2 h1:d/ATAG3MByySZgg7rFj+Wj0fhvP4zfx9Z8Dn/NSCoFg=
21-
go.bug.st/relaxed-semver v0.10.2/go.mod h1:lPVGdtzbQ9/2fv6iXqIXWHOj6cMTUJ/l/Lu1w+sgdio=
20+
go.bug.st/relaxed-semver v0.11.0 h1:ngzpUlBEZ5F9hJnMZP55LIFbgX3bCztBBufMhJViAsY=
21+
go.bug.st/relaxed-semver v0.11.0/go.mod h1:rqPEm+790OTQlAdfSJSHWwpKOg3A8UyvAWMZxYkQivc=
22+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2223
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2324
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2425
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)