Skip to content

Added version command #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/arduino/go-paths-helper"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

// RunPlugin runs the given plugin
Expand Down Expand Up @@ -100,13 +101,22 @@ func RunPlugin(plugin Plugin) {
}
certCmd.AddCommand(certFlashCmd)

versionCmd := &cobra.Command{
Use: "version",
Short: "Return informations about this fw-updater plugin",
Run: func(cmd *cobra.Command, args []string) {
printInfo(info)
},
}

appName := filepath.Base(os.Args[0])
cli := &cobra.Command{
Use: appName,
Short: info.Name + " - This is an Arduino Firmware Uploader plugin.",
}
cli.AddCommand(firmwareCmd)
cli.AddCommand(certCmd)
cli.AddCommand(versionCmd)
cli.PersistentFlags().StringVarP(&portAddress, "address", "p", "", "Port address")

if err := cli.Execute(); err != nil {
Expand All @@ -118,3 +128,18 @@ func fatal(msg string, exitcode int) {
fmt.Fprintf(os.Stderr, "Error: %s\n", msg)
os.Exit(exitcode)
}

func printInfo(info *PluginInfo) {
type infoResult struct {
PluginInfo *PluginInfo `yaml:"plugin_info"`
PluginAPIVersion int `yaml:"plugin_api_version"`
}
data, err := yaml.Marshal(&infoResult{
PluginAPIVersion: 1,
PluginInfo: info,
})
if err != nil {
fatal(err.Error(), 3)
}
fmt.Println(string(data))
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.20
require (
github.com/arduino/go-paths-helper v1.9.1
github.com/spf13/cobra v1.7.0
go.bug.st/relaxed-semver v0.10.2
go.bug.st/relaxed-semver v0.11.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
go.bug.st/relaxed-semver v0.10.2 h1:d/ATAG3MByySZgg7rFj+Wj0fhvP4zfx9Z8Dn/NSCoFg=
go.bug.st/relaxed-semver v0.10.2/go.mod h1:lPVGdtzbQ9/2fv6iXqIXWHOj6cMTUJ/l/Lu1w+sgdio=
go.bug.st/relaxed-semver v0.11.0 h1:ngzpUlBEZ5F9hJnMZP55LIFbgX3bCztBBufMhJViAsY=
go.bug.st/relaxed-semver v0.11.0/go.mod h1:rqPEm+790OTQlAdfSJSHWwpKOg3A8UyvAWMZxYkQivc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=