| 134 | } |
| 135 | |
| 136 | func PromptMissing(opts *CreateOptions) error { |
| 137 | if opts.Name.Value == "" { |
| 138 | if err := opts.Ask(&survey.Input{ |
| 139 | Message: "Name", |
| 140 | Help: "A short, memorable, unique name for this account.", |
| 141 | }, &opts.Name.Value, survey.WithValidator(survey.ComposeValidators( |
| 142 | survey.MaxLength(200), |
| 143 | survey.MinLength(1), |
| 144 | survey.Required, |
| 145 | ))); err != nil { |
| 146 | return err |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if opts.Description.Value == "" { |
| 151 | if err := opts.Ask(&surveyext.OctoEditor{ |
| 152 | Editor: &survey.Editor{ |
| 153 | Message: "Description", |
| 154 | Help: "A summary explaining the use of the account to other users.", |
| 155 | FileName: "*.md", |
| 156 | }, |
| 157 | Optional: true, |
| 158 | }, &opts.Description.Value); err != nil { |
| 159 | return err |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if opts.Token.Value == "" { |
| 164 | if err := opts.Ask(&survey.Password{ |
| 165 | Message: "Token", |
| 166 | Help: "The password to use to when authenticating against the remote host.", |
| 167 | }, &opts.Token.Value, survey.WithValidator(survey.ComposeValidators( |
| 168 | survey.Required, |
| 169 | ))); err != nil { |
| 170 | return err |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if opts.Environments.Value == nil { |
| 175 | envs, err := selectors.EnvironmentsMultiSelect(opts.Ask, opts.GetAllEnvironmentsCallback, |
| 176 | "Choose the environments that are allowed to use this account.\n"+ |
| 177 | output.Dim("If nothing is selected, the account can be used for deployments to any environment."), false) |
| 178 | if err != nil { |
| 179 | return err |
| 180 | } |
| 181 | opts.Environments.Value = util.SliceTransform(envs, func(e *environments.Environment) string { return e.ID }) |
| 182 | } |
| 183 | return nil |
| 184 | } |