@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/arduino/go-paths-helper"
25
25
"github.com/spf13/cobra"
26
+ "gopkg.in/yaml.v3"
26
27
)
27
28
28
29
// RunPlugin runs the given plugin
@@ -100,13 +101,22 @@ func RunPlugin(plugin Plugin) {
100
101
}
101
102
certCmd .AddCommand (certFlashCmd )
102
103
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
+
103
112
appName := filepath .Base (os .Args [0 ])
104
113
cli := & cobra.Command {
105
114
Use : appName ,
106
115
Short : info .Name + " - This is an Arduino Firmware Uploader plugin." ,
107
116
}
108
117
cli .AddCommand (firmwareCmd )
109
118
cli .AddCommand (certCmd )
119
+ cli .AddCommand (versionCmd )
110
120
cli .PersistentFlags ().StringVarP (& portAddress , "address" , "p" , "" , "Port address" )
111
121
112
122
if err := cli .Execute (); err != nil {
@@ -118,3 +128,18 @@ func fatal(msg string, exitcode int) {
118
128
fmt .Fprintf (os .Stderr , "Error: %s\n " , msg )
119
129
os .Exit (exitcode )
120
130
}
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
+ }
0 commit comments