-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppor for OTA status retrieval (#150)
* Added support for ota v2 * Fixed go compatibility * Fixed output for ota status * refactor: fix typos * Tagging improvements * Tag in case of v1.x lib update * Fixed compile * Removed not used param * Increased timeout --------- Co-authored-by: Roberto Gazia <[email protected]>
- Loading branch information
1 parent
4db92cc
commit 272e8c1
Showing
16 changed files
with
849 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This file is part of arduino-cloud-cli. | ||
// | ||
// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package ota | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/arduino/arduino-cli/cli/errorcodes" | ||
"github.com/arduino/arduino-cli/cli/feedback" | ||
"github.com/arduino/arduino-cloud-cli/command/ota" | ||
"github.com/arduino/arduino-cloud-cli/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type statusFlags struct { | ||
otaID string | ||
otaIDs string | ||
deviceId string | ||
limit int16 | ||
sort string | ||
} | ||
|
||
func initOtaStatusCommand() *cobra.Command { | ||
flags := &statusFlags{} | ||
uploadCommand := &cobra.Command{ | ||
Use: "status", | ||
Short: "OTA status", | ||
Long: "Get OTA status by OTA or device ID", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := runOtaStatusCommand(flags); err != nil { | ||
feedback.Errorf("Error during ota get status: %v", err) | ||
os.Exit(errorcodes.ErrGeneric) | ||
} | ||
}, | ||
} | ||
uploadCommand.Flags().StringVarP(&flags.otaID, "ota-id", "o", "", "OTA ID") | ||
uploadCommand.Flags().StringVarP(&flags.otaIDs, "ota-ids", "", "", "OTA IDs (comma separated)") | ||
uploadCommand.Flags().StringVarP(&flags.deviceId, "device-id", "d", "", "Device ID") | ||
uploadCommand.Flags().Int16VarP(&flags.limit, "limit", "l", 10, "Output limit (default: 10)") | ||
uploadCommand.Flags().StringVarP(&flags.sort, "sort", "s", "desc", "Sorting (default: desc)") | ||
|
||
return uploadCommand | ||
} | ||
|
||
func runOtaStatusCommand(flags *statusFlags) error { | ||
if flags.otaID == "" && flags.deviceId == "" && flags.otaIDs == "" { | ||
return fmt.Errorf("required flag(s) \"ota-id\" or \"device-id\" or \"ota-ids\" not set") | ||
} | ||
|
||
cred, err := config.RetrieveCredentials() | ||
if err != nil { | ||
return fmt.Errorf("retrieving credentials: %w", err) | ||
} | ||
|
||
return ota.PrintOtaStatus(flags.otaID, flags.otaIDs, flags.deviceId, cred, int(flags.limit), flags.sort) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.