/
sims_deactivate.go
104 lines (80 loc) · 2.22 KB
/
sims_deactivate.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Code generated by soracom-cli generate-cmd. DO NOT EDIT.
package cmd
import (
"fmt"
"net/url"
"os"
"github.com/spf13/cobra"
)
// SimsDeactivateCmdSimId holds value of 'sim_id' option
var SimsDeactivateCmdSimId string
func InitSimsDeactivateCmd() {
SimsDeactivateCmd.Flags().StringVar(&SimsDeactivateCmdSimId, "sim-id", "", TRAPI("SIM ID of the target SIM."))
SimsDeactivateCmd.RunE = SimsDeactivateCmdRunE
SimsCmd.AddCommand(SimsDeactivateCmd)
}
// SimsDeactivateCmd defines 'deactivate' subcommand
var SimsDeactivateCmd = &cobra.Command{
Use: "deactivate",
Short: TRAPI("/sims/{sim_id}/deactivate:post:summary"),
Long: TRAPI(`/sims/{sim_id}/deactivate:post:description`) + "\n\n" + createLinkToAPIReference("Sim", "deactivateSim"),
}
func SimsDeactivateCmdRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("unexpected arguments passed => %v", args)
}
opt := &apiClientOptions{
BasePath: "/v1",
Language: getSelectedLanguage(),
}
ac := newAPIClient(opt)
if v := os.Getenv("SORACOM_VERBOSE"); v != "" {
ac.SetVerbose(true)
}
err := ac.getAPICredentials()
if err != nil {
cmd.SilenceUsage = true
return err
}
param, err := collectSimsDeactivateCmdParams(ac)
if err != nil {
return err
}
body, err := ac.callAPI(param)
if err != nil {
cmd.SilenceUsage = true
return err
}
if body == "" {
return nil
}
if rawOutput {
_, err = os.Stdout.Write([]byte(body))
} else {
return prettyPrintStringAsJSON(body)
}
return err
}
func collectSimsDeactivateCmdParams(ac *apiClient) (*apiParams, error) {
var parsedBody interface{}
var err error
err = checkIfRequiredStringParameterIsSupplied("sim_id", "sim-id", "path", parsedBody, SimsDeactivateCmdSimId)
if err != nil {
return nil, err
}
return &apiParams{
method: "POST",
path: buildPathForSimsDeactivateCmd("/sims/{sim_id}/deactivate"),
query: buildQueryForSimsDeactivateCmd(),
noRetryOnError: noRetryOnError,
}, nil
}
func buildPathForSimsDeactivateCmd(path string) string {
escapedSimId := url.PathEscape(SimsDeactivateCmdSimId)
path = strReplace(path, "{"+"sim_id"+"}", escapedSimId, -1)
return path
}
func buildQueryForSimsDeactivateCmd() url.Values {
result := url.Values{}
return result
}