mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: prevent change in defaults if user unsets in template edit (#10793)
* fix: template edit not change defaults if user unset
This commit is contained in:
+14
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/cli/clibase"
|
||||
"github.com/coder/coder/v2/coderd/schedule/cron"
|
||||
"github.com/coder/coder/v2/coderd/util/tz"
|
||||
)
|
||||
@@ -18,6 +19,19 @@ var (
|
||||
errUnsupportedTimezone = xerrors.New("The location you provided looks like a timezone. Check https://ipinfo.io for your location.")
|
||||
)
|
||||
|
||||
// userSetOption returns true if the option was set by the user.
|
||||
// This is helpful if the zero value of a flag is meaningful, and you need
|
||||
// to distinguish between the user setting the flag to the zero value and
|
||||
// the user not setting the flag at all.
|
||||
func userSetOption(inv *clibase.Invocation, flagName string) bool {
|
||||
for _, opt := range inv.Command.Options {
|
||||
if opt.Name == flagName {
|
||||
return !(opt.ValueSource == clibase.ValueSourceNone || opt.ValueSource == clibase.ValueSourceDefault)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// durationDisplay formats a duration for easier display:
|
||||
// - Durations of 24 hours or greater are displays as Xd
|
||||
// - Durations less than 1 minute are displayed as <1m
|
||||
|
||||
Reference in New Issue
Block a user