(f factory.Factory)
| 59 | } |
| 60 | |
| 61 | func NewCmdCreate(f factory.Factory) *cobra.Command { |
| 62 | createFlags := NewCreateFlags() |
| 63 | descriptionFilePath := "" |
| 64 | |
| 65 | cmd := &cobra.Command{ |
| 66 | Use: "create", |
| 67 | Short: "Create a Username/Password account", |
| 68 | Long: "Create a Username/Password account in Octopus Deploy", |
| 69 | Example: heredoc.Docf(` |
| 70 | %s account username create" |
| 71 | `, constants.ExecutableName), |
| 72 | RunE: func(c *cobra.Command, _ []string) error { |
| 73 | opts := NewCreateOptions(createFlags, cmd.NewDependencies(f, c)) |
| 74 | if descriptionFilePath != "" { |
| 75 | if err := validation.IsExistingFile(descriptionFilePath); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | data, err := os.ReadFile(descriptionFilePath) |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | opts.Description.Value = string(data) |
| 83 | } |
| 84 | if opts.Environments.Value != nil { |
| 85 | env, err := helper.ResolveEnvironmentNames(opts.Environments.Value, opts.Client) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | opts.Environments.Value = env |
| 90 | } |
| 91 | return CreateRun(opts) |
| 92 | }, |
| 93 | } |
| 94 | |
| 95 | flags := cmd.Flags() |
| 96 | flags.StringVarP(&createFlags.Name.Value, createFlags.Name.Name, "n", "", "A short, memorable, unique name for this account.") |
| 97 | flags.StringVarP(&createFlags.Description.Value, createFlags.Description.Name, "d", "", "A summary explaining the use of the account to other users.") |
| 98 | flags.StringVarP(&createFlags.Username.Value, createFlags.Username.Name, "u", "", "The username to use when authenticating against the remote host.") |
| 99 | flags.StringVarP(&createFlags.Password.Value, createFlags.Password.Name, "p", "", "The password to use to when authenticating against the remote host.") |
| 100 | flags.StringArrayVarP(&createFlags.Environments.Value, createFlags.Environments.Name, "e", nil, "The environments that are allowed to use this account.") |
| 101 | flags.StringVarP(&descriptionFilePath, "description-file", "D", "", "Read the description from `file`.") |
| 102 | |
| 103 | return cmd |
| 104 | } |
| 105 | |
| 106 | func CreateRun(opts *CreateOptions) error { |
| 107 | if !opts.NoPrompt { |
nothing calls this directly
no test coverage detected