package main import ( "context" "encoding/json" "flag" "fmt" "log" "net/http" "os" ) // systemLegacyRoutesVerb is the line carlos system's usage puts under the // legacy-routes assign verb. const systemLegacyRoutesVerb = "say which account and app the routes an operator filed by hand belong to" // runSystemLegacyRoutesVerb is `carlos system legacy-routes assign` // (seeded-instances spec ยง6.4): which account and app the routes an // operator filed by hand under the operator account belong to. func runSystemLegacyRoutesVerb(rest []string) { if len(rest) == 0 || rest[0] != "assign" { systemUsage() os.Exit(2) } fs := flag.NewFlagSet("system legacy-routes assign", flag.ExitOnError) consoleFlag := consoleOption(fs, "console origin (default: the only logged-in one)") name := fs.String("name", "", "the app name the legacy routes are filed under, in the operator account") to := fs.String("to", "", "the account and app they belong to, as /") fs.Parse(rest[1:]) if *name == "" || *to == "" || fs.NArg() != 0 { fs.Usage() os.Exit(2) } sess := requireDeployAPISession(*consoleFlag) printUsing(stdout, sess) status, body, err := sess.postJSON(context.Background(), "/api/cli/system/legacy-routes", map[string]string{"name": *name, "to": *to}) if err != nil { log.Fatalf("carlos system legacy-routes assign: %v", err) } if status != http.StatusOK { log.Fatalf("carlos system legacy-routes assign: %v", apiErrorFromBody(status, body)) } var out struct { Name string `json:"name"` Account string `json:"account"` App string `json:"app"` } if err := json.Unmarshal(body, &out); err != nil { log.Fatalf("carlos system legacy-routes assign: unreadable response: %v", err) } fmt.Fprintln(stdout, fmt.Sprintf("assigned the legacy routes named %s to %s/%s", out.Name, out.Account, out.App)) }