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