@@ -58,6 +58,7 @@ import (
5858
5959var (
6060 verbose bool
61+ jsonOutput bool
6162 outputFormat string
6263 configFile string
6364)
@@ -75,6 +76,10 @@ func NewCommand() *cobra.Command {
7576 Long : tr ("Arduino Command Line Interface (arduino-cli)." ),
7677 Example : fmt .Sprintf (" %s <%s> [%s...]" , os .Args [0 ], tr ("command" ), tr ("flags" )),
7778 PersistentPreRun : func (cmd * cobra.Command , args []string ) {
79+ if jsonOutput {
80+ outputFormat = "json"
81+ }
82+
7883 preRun (cmd , args )
7984
8085 if cmd .Name () != "version" {
@@ -155,6 +160,8 @@ func createCliCommandTree(cmd *cobra.Command) {
155160 cmd .RegisterFlagCompletionFunc ("format" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
156161 return validOutputFormats , cobra .ShellCompDirectiveDefault
157162 })
163+ cmd .Flag ("format" ).Hidden = true
164+ cmd .PersistentFlags ().BoolVar (& jsonOutput , "json" , false , tr ("Print the output in JSON format." ))
158165 cmd .PersistentFlags ().StringVar (& configFile , "config-file" , "" , tr ("The custom config file (if not specified the default will be used)." ))
159166 cmd .PersistentFlags ().StringSlice ("additional-urls" , []string {}, tr ("Comma-separated list of additional URLs for the Boards Manager." ))
160167 cmd .PersistentFlags ().Bool ("no-color" , false , "Disable colored output." )
0 commit comments