Skip to content

Commit 78ee1db

Browse files
authored
add support for network commands (#35)
* add support for valid empty POST responses (used by network commands) * add support for more generic simple json response * add supports param to schema to sync server and cli compatibility
1 parent ce19760 commit 78ee1db

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cmd/command_Post.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,35 @@ func commandRunPost(cmd *cobra.Command, command SchemaCommand) {
9797
}
9898
commandRunSsh(cmd, command, body, publicKey)
9999
os.Exit(exitCodeUnexpected)
100+
} else if command.Run.SimpleJsonServerResponse {
101+
if format == "json" {
102+
fmt.Println(string(body))
103+
os.Exit(0)
104+
} else {
105+
var response map[string]string
106+
if err := json.Unmarshal(body, &response); err != nil {
107+
fmt.Println(string(body))
108+
fmt.Println("Failed to parse server response")
109+
os.Exit(exitCodeInvalidResponse)
110+
} else if format == "yaml" {
111+
var d []byte
112+
d, err = yaml.Marshal(&response)
113+
if err != nil {
114+
fmt.Println(string(body))
115+
fmt.Println("Invalid response from server")
116+
os.Exit(exitCodeInvalidResponse)
117+
} else {
118+
fmt.Println(string(d))
119+
os.Exit(0)
120+
}
121+
} else {
122+
message, hasMessage := response["message"]
123+
if hasMessage {
124+
fmt.Println(message)
125+
os.Exit(0)
126+
}
127+
}
128+
}
100129
} else {
101130
var commandIds []string;
102131
if err := json.Unmarshal(body, &commandIds); err != nil {

cmd/command_schema.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type SchemaCommandRun struct {
7474
Lists []SchemaCommandList `json:"lists"`
7575
ServerMethod string `json:"serverMethod"`
7676
ParseStatisticsResponse bool `json:"ParseStatisticsResponse"`
77+
SimpleJsonServerResponse bool `json:"SimpleJsonServerResponse"`
7778
}
7879

7980
type SchemaCommandCliPreRunHook struct {
@@ -104,7 +105,13 @@ type Schema struct {
104105
SchemaGeneratedAt time.Time `json:"schema_generated_at"`
105106
}
106107

108+
func getSupportsParam() string {
109+
// comma-separated list of cloudcli-server functionality this cli version supports
110+
return "SimpleJsonServerResponse"
111+
}
112+
107113
func downloadSchema(schemaFile string, schemaUrl string) Schema {
114+
schemaUrl = fmt.Sprintf("%s?supports=%s", schemaUrl, getSupportsParam())
108115
var schema_ Schema
109116
if dryrun || debug {
110117
if debug {

0 commit comments

Comments
 (0)