|
| 1 | +// This file is part of arduino-cloud-cli. |
| 2 | +// |
| 3 | +// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Affero General Public License as published |
| 7 | +// by the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Affero General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Affero General Public License |
| 16 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +package device |
| 19 | + |
| 20 | +import ( |
| 21 | + "os" |
| 22 | + |
| 23 | + "github.com/arduino/arduino-cli/cli/errorcodes" |
| 24 | + "github.com/arduino/arduino-cli/cli/feedback" |
| 25 | + "github.com/arduino/arduino-cli/table" |
| 26 | + "github.com/arduino/arduino-cloud-cli/command/device" |
| 27 | + "github.com/sirupsen/logrus" |
| 28 | + "github.com/spf13/cobra" |
| 29 | +) |
| 30 | + |
| 31 | +func initListFQBNCommand() *cobra.Command { |
| 32 | + listFQBNCommand := &cobra.Command{ |
| 33 | + Use: "list-fqbn", |
| 34 | + Short: "List supported FQBN", |
| 35 | + Long: "List all the FQBN supported by Arduino IoT Cloud", |
| 36 | + Run: runListFQBNCommand, |
| 37 | + } |
| 38 | + return listFQBNCommand |
| 39 | +} |
| 40 | + |
| 41 | +func runListFQBNCommand(cmd *cobra.Command, args []string) { |
| 42 | + logrus.Info("Listing supported FQBN") |
| 43 | + |
| 44 | + fqbn, err := device.ListFQBN() |
| 45 | + if err != nil { |
| 46 | + feedback.Errorf("Error during device list-fqbn: %v", err) |
| 47 | + os.Exit(errorcodes.ErrGeneric) |
| 48 | + } |
| 49 | + |
| 50 | + feedback.PrintResult(listFQBNResult{fqbn}) |
| 51 | +} |
| 52 | + |
| 53 | +type listFQBNResult struct { |
| 54 | + fqbn []device.FQBNInfo |
| 55 | +} |
| 56 | + |
| 57 | +func (r listFQBNResult) Data() interface{} { |
| 58 | + return r.fqbn |
| 59 | +} |
| 60 | + |
| 61 | +func (r listFQBNResult) String() string { |
| 62 | + if len(r.fqbn) == 0 { |
| 63 | + return "No FQBN." |
| 64 | + } |
| 65 | + t := table.New() |
| 66 | + t.SetHeader("Name", "FQBN") |
| 67 | + for _, f := range r.fqbn { |
| 68 | + t.AddRow( |
| 69 | + f.Name, |
| 70 | + f.FQBN, |
| 71 | + ) |
| 72 | + } |
| 73 | + return t.Render() |
| 74 | +} |
0 commit comments