-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract.go
43 lines (35 loc) · 1.05 KB
/
extract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package thing
import (
"fmt"
"github.com/arduino/iot-cloud-cli/command/thing"
"github.com/spf13/cobra"
)
var extractFlags struct {
id string
outfile string
}
func initExtractCommand() *cobra.Command {
extractCommand := &cobra.Command{
Use: "extract",
Short: "Extract a template from a thing",
Long: "Extract a template from a Arduino IoT Cloud thing and save it in a file",
RunE: runExtractCommand,
}
extractCommand.Flags().StringVarP(&extractFlags.id, "id", "i", "", "Thing ID")
extractCommand.Flags().StringVarP(&extractFlags.outfile, "outfile", "o", "", "Template file destination path")
extractCommand.MarkFlagRequired("id")
return extractCommand
}
func runExtractCommand(cmd *cobra.Command, args []string) error {
fmt.Printf("Extracting template from thing %s\n", extractFlags.id)
params := &thing.ExtractParams{ID: extractFlags.id}
if extractFlags.outfile != "" {
params.Outfile = &extractFlags.outfile
}
err := thing.Extract(params)
if err != nil {
return err
}
fmt.Println("Template successfully extracted")
return nil
}