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 doUpdate(baseurl, architecture string) { url := fmt.Sprintf("%s/sail-%s", baseurl, architecture) if internal.Verbose { fmt.Fprintf(os.Stderr, "Debug: updating from %s\n", url) } resp, err := http.Get(url) if err != nil { internal.Exit("Error when downloading sail\n", err) } defer resp.Body.Close() err = update.Apply(resp.Body, update.Options{}) if err != nil { internal.Exit("Error when updating sail\n", err) } }
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"]) } } }
func cmdGet(cmd *cobra.Command, args []string) { // FIXME: duplicate internal.ReadConfig() var ns string // Check args if len(args) > 1 { internal.Exit("Invalid usage. sail compose get [--standard] [<application>]. Please see sail compose get -h\n") } else if len(args) > 1 { ns = args[0] } else { ns = internal.User } path := fmt.Sprintf("/applications/%s/fig?standard=%v", ns, getStandard) data, _, err := internal.Request("GET", path, nil) if err != nil { internal.Exit("Error: %s\n", err) } fmt.Printf("%s", data) }