func cmdUp(cmd *cobra.Command, args []string) { // Check args if len(args) != 1 { internal.Exit("Invalid usage. sail compose up <namespace>. Please see sail compose up -h\n") } ns := args[0] // Try to read file payload, err := ioutil.ReadFile(upFile) if err != nil { internal.Exit("Error reading compose file: %s\n", err) } // Execute request path := fmt.Sprintf("/applications/%s/fig/up?stream", ns) buffer, _, err := internal.Stream("POST", path, payload, internal.SetHeader("Content-Type", "application/x-yaml")) internal.Check(err) // Display api stream line, err := internal.DisplayStream(buffer) internal.Check(err) if line != nil { var data map[string]interface{} err = json.Unmarshal(line, &data) internal.Check(err) fmt.Printf("Hostname: %v\n", data["hostname"]) fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"]) } }
func cmdUp(cmd *cobra.Command, args []string) { // FIXME: duplicate internal.ReadConfig() var ns string // Check args if len(args) > 1 { internal.Exit("Invalid usage. sail compose up [<application>]. Please see sail compose up -h\n") } else if len(args) > 1 { ns = args[0] } else { ns = internal.User } // Try to read file payload, err := ioutil.ReadFile(upFile) if err != nil { internal.Exit("Error reading compose file: %s\n", err) } // Execute request path := fmt.Sprintf("/applications/%s/fig/up", ns) buffer, _, err := internal.Stream("POST", path, payload, internal.SetHeader("Content-Type", "application/x-yaml")) internal.Check(err) // Display api stream line, err := internal.DisplayStream(buffer) internal.Check(err) if len(line) > 0 { var data []map[string]interface{} err = json.Unmarshal(line, &data) if err != nil { fmt.Printf("Error detected in API Return. Line: %s\n", line) return } for i := range data { fmt.Printf("Compose operation for service %v is %v\n", data[i]["name"], data[i]["result"]) } } }