(env *cliconfig.Environment, defaults cliconfig.Environment)
| 157 | } |
| 158 | |
| 159 | func promptEnv(env *cliconfig.Environment, defaults cliconfig.Environment) error { |
| 160 | if env.OperatorEndpoint == "" { |
| 161 | fmt.Print("you can get your cortex operator endpoint using `cortex cluster info` if you already have a cortex cluster running, otherwise run `cortex cluster up` to create a cortex cluster\n\n") |
| 162 | } |
| 163 | |
| 164 | validator := func(endpoint string) (string, error) { |
| 165 | operatorURL, err := validateOperatorEndpoint(endpoint) |
| 166 | if err != nil { |
| 167 | return "", err |
| 168 | } |
| 169 | |
| 170 | return operatorURL, nil |
| 171 | } |
| 172 | |
| 173 | for true { |
| 174 | err := cr.ReadPrompt(env, &cr.PromptValidation{ |
| 175 | SkipNonEmptyFields: true, |
| 176 | PromptItemValidations: []*cr.PromptItemValidation{ |
| 177 | { |
| 178 | StructField: "Name", |
| 179 | PromptOpts: &prompt.Options{ |
| 180 | Prompt: "name of environment to create or update", |
| 181 | }, |
| 182 | StringValidation: &cr.StringValidation{ |
| 183 | Required: true, |
| 184 | }, |
| 185 | }, |
| 186 | { |
| 187 | StructField: "OperatorEndpoint", |
| 188 | PromptOpts: &prompt.Options{ |
| 189 | Prompt: "cortex operator endpoint", |
| 190 | }, |
| 191 | StringValidation: &cr.StringValidation{ |
| 192 | Required: true, |
| 193 | Default: defaults.OperatorEndpoint, |
| 194 | Validator: validator, |
| 195 | }, |
| 196 | }, |
| 197 | }, |
| 198 | }) |
| 199 | if err != nil { |
| 200 | return err |
| 201 | } |
| 202 | |
| 203 | return nil |
| 204 | } |
| 205 | |
| 206 | return nil |
| 207 | } |
| 208 | |
| 209 | // Only validate this during prompt, not when reading from file |
| 210 | func validateOperatorEndpoint(endpoint string) (string, error) { |
no test coverage detected