(f factory.Factory)
| 75 | } |
| 76 | |
| 77 | func NewUpdateCmd(f factory.Factory) *cobra.Command { |
| 78 | updateFlags := NewUpdateFlags() |
| 79 | cmd := &cobra.Command{ |
| 80 | Use: "update", |
| 81 | Short: "Update the value of a project variable", |
| 82 | Long: "Update the value of a project variable in Octopus Deploy", |
| 83 | Example: heredoc.Docf(` |
| 84 | %[1]s project variable update |
| 85 | %[1]s project variable update --name "variable name" --value "abc" |
| 86 | %[1]s project variable update --name "variable name" --value "password" |
| 87 | %[1]s project variable update --name "variable name" --unscoped |
| 88 | %[1]s project variable update --name "variable name" --environment-scope test |
| 89 | %[1]s project variable update -p "Deploy Website" --name "variable name" --value "updated" --git-ref refs/heads/main |
| 90 | `, constants.ExecutableName), |
| 91 | RunE: func(c *cobra.Command, args []string) error { |
| 92 | opts := NewUpdateOptions(updateFlags, cmd.NewDependencies(f, c)) |
| 93 | |
| 94 | return updateRun(opts) |
| 95 | }, |
| 96 | } |
| 97 | |
| 98 | flags := cmd.Flags() |
| 99 | flags.StringVar(&updateFlags.Id.Value, updateFlags.Id.Name, "", "The variable id to update") |
| 100 | flags.StringVarP(&updateFlags.Project.Value, updateFlags.Project.Name, "p", "", "The project") |
| 101 | flags.StringVarP(&updateFlags.Name.Value, updateFlags.Name.Name, "n", "", "The name of the variable") |
| 102 | flags.StringVar(&updateFlags.Value.Value, updateFlags.Value.Name, "", "The value to set on the variable") |
| 103 | flags.BoolVar(&updateFlags.Unscoped.Value, updateFlags.Unscoped.Name, false, "Remove all shared from the variable, cannot be used with shared") |
| 104 | flags.StringVarP(&updateFlags.GitRef.Value, updateFlags.GitRef.Name, "", "", "The GitRef for the Config-As-Code branch") |
| 105 | sharedProjectVariable.RegisterScopeFlags(cmd, updateFlags.ScopeFlags) |
| 106 | |
| 107 | return cmd |
| 108 | } |
| 109 | |
| 110 | func updateRun(opts *UpdateOptions) error { |
| 111 | if opts.Unscoped.Value && scopesProvided(opts) { |
nothing calls this directly
no test coverage detected