Run make fmt

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
Hubertbits 2025-04-12 00:19:15 +02:00 committed by yxxhero
parent a829524fc3
commit e8a4380e66
24 changed files with 440 additions and 445 deletions

View File

@ -73,7 +73,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.StringArrayVar(&applyOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output") f.StringArrayVar(&applyOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output")
// Register flags using the registrar // Register flags using the registrar
flagRegistrar.RegisterFlags(cmd) flagRegistrar.RegisterFlags(cmd)
return cmd return cmd
} }

View File

@ -62,7 +62,7 @@ func NewDiffCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.StringArrayVar(&diffOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output") f.StringArrayVar(&diffOptions.SuppressOutputLineRegex, "suppress-output-line-regex", nil, "a list of regex patterns to suppress output lines from the diff output")
// Register flags using the registrar // Register flags using the registrar
flagRegistrar.RegisterFlags(cmd) flagRegistrar.RegisterFlags(cmd)
return cmd return cmd
} }

View File

@ -1377,7 +1377,7 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) {
SkipDiffOnInstall: c.SkipDiffOnInstall(), SkipDiffOnInstall: c.SkipDiffOnInstall(),
ReuseValues: c.ReuseValues(), ReuseValues: c.ReuseValues(),
ResetValues: c.ResetValues(), ResetValues: c.ResetValues(),
IncludeCRDs: c.ShouldIncludeCRDs(), IncludeCRDs: c.ShouldIncludeCRDs(),
DiffArgs: c.DiffArgs(), DiffArgs: c.DiffArgs(),
PostRenderer: c.PostRenderer(), PostRenderer: c.PostRenderer(),
PostRendererArgs: c.PostRendererArgs(), PostRendererArgs: c.PostRendererArgs(),

View File

@ -244,9 +244,9 @@ type TemplateConfigProvider interface {
} }
type CRDConfig interface { type CRDConfig interface {
SkipCRDs() bool SkipCRDs() bool
IncludeCRDs() bool IncludeCRDs() bool
ShouldIncludeCRDs() bool ShouldIncludeCRDs() bool
} }
type DAGConfig interface { type DAGConfig interface {

View File

@ -25,7 +25,7 @@ type diffConfig struct {
set []string set []string
validate bool validate bool
skipCRDs common.BoolFlag skipCRDs common.BoolFlag
includeCRDs common.BoolFlag includeCRDs common.BoolFlag
skipDeps bool skipDeps bool
skipRefresh bool skipRefresh bool
includeTests bool includeTests bool
@ -104,10 +104,10 @@ func (a diffConfig) IncludeCRDs() bool {
} }
func (a diffConfig) ShouldIncludeCRDs() bool { func (a diffConfig) ShouldIncludeCRDs() bool {
includeCRDsExplicit := a.includeCRDs.WasExplicitlySet() && a.includeCRDs.Value() includeCRDsExplicit := a.includeCRDs.WasExplicitlySet() && a.includeCRDs.Value()
skipCRDsExplicit := a.skipCRDs.WasExplicitlySet() && !a.skipCRDs.Value() skipCRDsExplicit := a.skipCRDs.WasExplicitlySet() && !a.skipCRDs.Value()
return includeCRDsExplicit || skipCRDsExplicit return includeCRDsExplicit || skipCRDsExplicit
} }
func (a diffConfig) SkipDeps() bool { func (a diffConfig) SkipDeps() bool {

View File

@ -2,42 +2,42 @@ package common
// BoolFlag represents a boolean flag that tracks whether it was explicitly set // BoolFlag represents a boolean flag that tracks whether it was explicitly set
type BoolFlag interface { type BoolFlag interface {
// Value returns the current boolean value // Value returns the current boolean value
Value() bool Value() bool
// WasExplicitlySet returns whether the flag was explicitly set // WasExplicitlySet returns whether the flag was explicitly set
WasExplicitlySet() bool WasExplicitlySet() bool
// Set sets the value and marks the flag as explicitly set // Set sets the value and marks the flag as explicitly set
Set(value bool) Set(value bool)
} }
// boolFlag is the implementation of BoolFlag // boolFlag is the implementation of BoolFlag
type boolFlag struct { type boolFlag struct {
value bool value bool
wasExplicitlySet bool wasExplicitlySet bool
} }
// NewBoolFlag creates a new BoolFlag with default values // NewBoolFlag creates a new BoolFlag with default values
func NewBoolFlag(defaultValue bool) BoolFlag { func NewBoolFlag(defaultValue bool) BoolFlag {
return &boolFlag{ return &boolFlag{
value: defaultValue, value: defaultValue,
wasExplicitlySet: false, wasExplicitlySet: false,
} }
} }
// Value returns the current boolean value // Value returns the current boolean value
func (bf *boolFlag) Value() bool { func (bf *boolFlag) Value() bool {
return bf.value return bf.value
} }
// WasExplicitlySet returns whether the flag was explicitly set // WasExplicitlySet returns whether the flag was explicitly set
func (bf *boolFlag) WasExplicitlySet() bool { func (bf *boolFlag) WasExplicitlySet() bool {
return bf.wasExplicitlySet return bf.wasExplicitlySet
} }
// Set sets the value and marks the flag as explicitly set // Set sets the value and marks the flag as explicitly set
func (bf *boolFlag) Set(value bool) { func (bf *boolFlag) Set(value bool) {
bf.value = value bf.value = value
bf.wasExplicitlySet = true bf.wasExplicitlySet = true
} }

View File

@ -1,94 +1,94 @@
package common package common
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestNewBoolFlag(t *testing.T) { func TestNewBoolFlag(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
defaultValue bool defaultValue bool
expected bool expected bool
}{ }{
{ {
name: "default true", name: "default true",
defaultValue: true, defaultValue: true,
expected: true, expected: true,
}, },
{ {
name: "default false", name: "default false",
defaultValue: false, defaultValue: false,
expected: false, expected: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
flag := NewBoolFlag(tt.defaultValue) flag := NewBoolFlag(tt.defaultValue)
// Check initial state // Check initial state
assert.Equal(t, tt.expected, flag.Value(), "Value should match default") assert.Equal(t, tt.expected, flag.Value(), "Value should match default")
assert.False(t, flag.WasExplicitlySet(), "New flag should not be marked as explicitly set") assert.False(t, flag.WasExplicitlySet(), "New flag should not be marked as explicitly set")
}) })
} }
} }
func TestBoolFlag_Set(t *testing.T) { func TestBoolFlag_Set(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
defaultValue bool defaultValue bool
setValue bool setValue bool
expected bool expected bool
}{ }{
{ {
name: "default false, set true", name: "default false, set true",
defaultValue: false, defaultValue: false,
setValue: true, setValue: true,
expected: true, expected: true,
}, },
{ {
name: "default true, set false", name: "default true, set false",
defaultValue: true, defaultValue: true,
setValue: false, setValue: false,
expected: false, expected: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
flag := NewBoolFlag(tt.defaultValue) flag := NewBoolFlag(tt.defaultValue)
// Set the value // Set the value
flag.Set(tt.setValue) flag.Set(tt.setValue)
// Check state after setting // Check state after setting
assert.Equal(t, tt.expected, flag.Value(), "Value should match set value") assert.Equal(t, tt.expected, flag.Value(), "Value should match set value")
assert.True(t, flag.WasExplicitlySet(), "Flag should be marked as explicitly set") assert.True(t, flag.WasExplicitlySet(), "Flag should be marked as explicitly set")
}) })
} }
} }
func TestBoolFlag_MultipleSet(t *testing.T) { func TestBoolFlag_MultipleSet(t *testing.T) {
flag := NewBoolFlag(false) flag := NewBoolFlag(false)
// Initial state // Initial state
assert.False(t, flag.Value()) assert.False(t, flag.Value())
assert.False(t, flag.WasExplicitlySet()) assert.False(t, flag.WasExplicitlySet())
// First set // First set
flag.Set(true) flag.Set(true)
assert.True(t, flag.Value()) assert.True(t, flag.Value())
assert.True(t, flag.WasExplicitlySet()) assert.True(t, flag.WasExplicitlySet())
// Second set // Second set
flag.Set(false) flag.Set(false)
assert.False(t, flag.Value()) assert.False(t, flag.Value())
assert.True(t, flag.WasExplicitlySet(), "Flag should remain explicitly set") assert.True(t, flag.WasExplicitlySet(), "Flag should remain explicitly set")
} }
func TestBoolFlag_Implementation(t *testing.T) { func TestBoolFlag_Implementation(t *testing.T) {
// Test that boolFlag properly implements BoolFlag interface // Test that boolFlag properly implements BoolFlag interface
var _ BoolFlag = &boolFlag{} var _ BoolFlag = &boolFlag{}
} }

View File

@ -1,58 +1,56 @@
package common package common
// For array/slice flags // For array/slice flags
type StringArrayFlag interface { type StringArrayFlag interface {
Values() []string Values() []string
WasExplicitlySet() bool WasExplicitlySet() bool
Add(value string) Add(value string)
Set(values []string) Set(values []string)
} }
type stringArrayFlag struct { type stringArrayFlag struct {
values []string values []string
wasExplicitlySet bool wasExplicitlySet bool
} }
// NewStringArrayFlag creates a new StringArrayFlag with the given default values // NewStringArrayFlag creates a new StringArrayFlag with the given default values
// Create a defensive copy of the default values to prevent external modifications // Create a defensive copy of the default values to prevent external modifications
// and to ensure that the original values remain unchanged. // and to ensure that the original values remain unchanged.
func NewStringArrayFlag(defaultValues []string) StringArrayFlag { func NewStringArrayFlag(defaultValues []string) StringArrayFlag {
valuesCopy := make([]string, len(defaultValues)) valuesCopy := make([]string, len(defaultValues))
copy(valuesCopy, defaultValues) copy(valuesCopy, defaultValues)
return &stringArrayFlag{ return &stringArrayFlag{
values: valuesCopy, values: valuesCopy,
wasExplicitlySet: false, wasExplicitlySet: false,
} }
} }
// Values returns the values of the flag // Values returns the values of the flag
// It returns a copy of the values to prevent external modifications // It returns a copy of the values to prevent external modifications
// and to ensure that the original values remain unchanged. // and to ensure that the original values remain unchanged.
// This is important for flags that may be modified by the user // This is important for flags that may be modified by the user
// or other parts of the program. // or other parts of the program.
func (f *stringArrayFlag) Values() []string { func (f *stringArrayFlag) Values() []string {
// Return a copy to prevent external modifications // Return a copy to prevent external modifications
valuesCopy := make([]string, len(f.values)) valuesCopy := make([]string, len(f.values))
copy(valuesCopy, f.values) copy(valuesCopy, f.values)
return valuesCopy return valuesCopy
} }
// WasExplicitlySet returns whether the flag was explicitly set // WasExplicitlySet returns whether the flag was explicitly set
func (f *stringArrayFlag) WasExplicitlySet() bool { func (f *stringArrayFlag) WasExplicitlySet() bool {
return f.wasExplicitlySet return f.wasExplicitlySet
} }
// Set sets the values and marks the flag as explicitly set // Set sets the values and marks the flag as explicitly set
func (f *stringArrayFlag) Set(values []string) { func (f *stringArrayFlag) Set(values []string) {
f.values = values f.values = values
f.wasExplicitlySet = true f.wasExplicitlySet = true
} }
// Add sets the value and marks the flag as explicitly set // Add sets the value and marks the flag as explicitly set
func (f *stringArrayFlag) Add(value string) { func (f *stringArrayFlag) Add(value string) {
f.values = append(f.values, value) f.values = append(f.values, value)
f.wasExplicitlySet = true f.wasExplicitlySet = true
} }

View File

@ -1,35 +1,35 @@
package common package common
type StringFlag interface { type StringFlag interface {
Value() string Value() string
WasExplicitlySet() bool WasExplicitlySet() bool
Set(value string) Set(value string)
} }
type stringFlag struct { type stringFlag struct {
value string value string
wasExplicitlySet bool wasExplicitlySet bool
} }
func NewStringFlag(defaultValue string) StringFlag { func NewStringFlag(defaultValue string) StringFlag {
return &stringFlag{ return &stringFlag{
value: defaultValue, value: defaultValue,
wasExplicitlySet: false, wasExplicitlySet: false,
} }
} }
// Value returns the current boolean value // Value returns the current boolean value
func (f *stringFlag) Value() string { func (f *stringFlag) Value() string {
return f.value return f.value
} }
// WasExplicitlySet returns whether the flag was explicitly set // WasExplicitlySet returns whether the flag was explicitly set
func (f *stringFlag) WasExplicitlySet() bool { func (f *stringFlag) WasExplicitlySet() bool {
return f.wasExplicitlySet return f.wasExplicitlySet
} }
// Set sets the value and marks the flag as explicitly set // Set sets the value and marks the flag as explicitly set
func (f *stringFlag) Set(value string) { func (f *stringFlag) Set(value string) {
f.value = value f.value = value
f.wasExplicitlySet = true f.wasExplicitlySet = true
} }

View File

@ -1,100 +1,100 @@
package common package common
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestNewStringFlag(t *testing.T) { func TestNewStringFlag(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
defaultValue string defaultValue string
expected string expected string
}{ }{
{ {
name: "empty default", name: "empty default",
defaultValue: "", defaultValue: "",
expected: "", expected: "",
}, },
{ {
name: "non-empty default", name: "non-empty default",
defaultValue: "default", defaultValue: "default",
expected: "default", expected: "default",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
flag := NewStringFlag(tt.defaultValue) flag := NewStringFlag(tt.defaultValue)
// Check initial state // Check initial state
assert.Equal(t, tt.expected, flag.Value(), "Value should match default") assert.Equal(t, tt.expected, flag.Value(), "Value should match default")
assert.False(t, flag.WasExplicitlySet(), "New flag should not be marked as explicitly set") assert.False(t, flag.WasExplicitlySet(), "New flag should not be marked as explicitly set")
}) })
} }
} }
func TestStringFlag_Set(t *testing.T) { func TestStringFlag_Set(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
defaultValue string defaultValue string
setValue string setValue string
expected string expected string
}{ }{
{ {
name: "empty default, set value", name: "empty default, set value",
defaultValue: "", defaultValue: "",
setValue: "new value", setValue: "new value",
expected: "new value", expected: "new value",
}, },
{ {
name: "non-empty default, set empty", name: "non-empty default, set empty",
defaultValue: "default", defaultValue: "default",
setValue: "", setValue: "",
expected: "", expected: "",
}, },
{ {
name: "non-empty default, set new value", name: "non-empty default, set new value",
defaultValue: "default", defaultValue: "default",
setValue: "new value", setValue: "new value",
expected: "new value", expected: "new value",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
flag := NewStringFlag(tt.defaultValue) flag := NewStringFlag(tt.defaultValue)
// Set the value // Set the value
flag.Set(tt.setValue) flag.Set(tt.setValue)
// Check state after setting // Check state after setting
assert.Equal(t, tt.expected, flag.Value(), "Value should match set value") assert.Equal(t, tt.expected, flag.Value(), "Value should match set value")
assert.True(t, flag.WasExplicitlySet(), "Flag should be marked as explicitly set") assert.True(t, flag.WasExplicitlySet(), "Flag should be marked as explicitly set")
}) })
} }
} }
func TestStringFlag_MultipleSet(t *testing.T) { func TestStringFlag_MultipleSet(t *testing.T) {
flag := NewStringFlag("initial") flag := NewStringFlag("initial")
// Initial state // Initial state
assert.Equal(t, "initial", flag.Value()) assert.Equal(t, "initial", flag.Value())
assert.False(t, flag.WasExplicitlySet()) assert.False(t, flag.WasExplicitlySet())
// First set // First set
flag.Set("first") flag.Set("first")
assert.Equal(t, "first", flag.Value()) assert.Equal(t, "first", flag.Value())
assert.True(t, flag.WasExplicitlySet()) assert.True(t, flag.WasExplicitlySet())
// Second set // Second set
flag.Set("second") flag.Set("second")
assert.Equal(t, "second", flag.Value()) assert.Equal(t, "second", flag.Value())
assert.True(t, flag.WasExplicitlySet(), "Flag should remain explicitly set") assert.True(t, flag.WasExplicitlySet(), "Flag should remain explicitly set")
} }
func TestStringFlag_Implementation(t *testing.T) { func TestStringFlag_Implementation(t *testing.T) {
// Test that stringFlag properly implements StringFlag interface // Test that stringFlag properly implements StringFlag interface
var _ StringFlag = &stringFlag{} var _ StringFlag = &stringFlag{}
} }

View File

@ -160,20 +160,20 @@ func (a *ApplyImpl) NoHooks() bool {
// SkipCRDs returns the skip CRDs. // SkipCRDs returns the skip CRDs.
func (a *ApplyImpl) SkipCRDs() bool { func (a *ApplyImpl) SkipCRDs() bool {
return a.ApplyOptions.SkipCRDsFlag.Value() return a.ApplyOptions.SkipCRDsFlag.Value()
} }
// IncludeCRDs returns the include CRDs. // IncludeCRDs returns the include CRDs.
func (a *ApplyImpl) IncludeCRDs() bool { func (a *ApplyImpl) IncludeCRDs() bool {
return a.ApplyOptions.IncludeCRDsFlag.Value() return a.ApplyOptions.IncludeCRDsFlag.Value()
} }
// ShouldIncludeCRDs returns true if CRDs should be included. // ShouldIncludeCRDs returns true if CRDs should be included.
func (a *ApplyImpl) ShouldIncludeCRDs() bool { func (a *ApplyImpl) ShouldIncludeCRDs() bool {
includeCRDsExplicit := a.IncludeCRDsFlag.WasExplicitlySet() && a.IncludeCRDsFlag.Value() includeCRDsExplicit := a.IncludeCRDsFlag.WasExplicitlySet() && a.IncludeCRDsFlag.Value()
skipCRDsExplicit := a.SkipCRDsFlag.WasExplicitlySet() && !a.SkipCRDsFlag.Value() skipCRDsExplicit := a.SkipCRDsFlag.WasExplicitlySet() && !a.SkipCRDsFlag.Value()
return includeCRDsExplicit || skipCRDsExplicit return includeCRDsExplicit || skipCRDsExplicit
} }
// SkipCleanup returns the skip cleanup. // SkipCleanup returns the skip cleanup.

View File

@ -157,20 +157,20 @@ func (t *DiffImpl) NoHooks() bool {
// SkipCRDs returns the skip crds // SkipCRDs returns the skip crds
func (t *DiffImpl) SkipCRDs() bool { func (t *DiffImpl) SkipCRDs() bool {
return t.DiffOptions.SkipCRDsFlag.Value() return t.DiffOptions.SkipCRDsFlag.Value()
} }
// IncludeCRDs returns the include crds // IncludeCRDs returns the include crds
func (t *DiffImpl) IncludeCRDs() bool { func (t *DiffImpl) IncludeCRDs() bool {
return t.DiffOptions.IncludeCRDsFlag.Value() return t.DiffOptions.IncludeCRDsFlag.Value()
} }
// ShouldIncludeCRDs returns true if CRDs should be included // ShouldIncludeCRDs returns true if CRDs should be included
func (t *DiffImpl) ShouldIncludeCRDs() bool { func (t *DiffImpl) ShouldIncludeCRDs() bool {
includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value() includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value()
skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value() skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value()
return includeCRDsExplicit || skipCRDsExplicit return includeCRDsExplicit || skipCRDsExplicit
} }
// SkipDiffOnInstall returns the skip diff on install // SkipDiffOnInstall returns the skip diff on install

View File

@ -1,65 +1,65 @@
package config package config
func (o *ApplyOptions) HandleFlag(name string, value interface{}, changed bool) { func (o *ApplyOptions) HandleFlag(name string, value interface{}, changed bool) {
if !changed { if !changed {
return return
} }
switch name { switch name {
case "include-crds": case "include-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.IncludeCRDsFlag.Set(*boolVal) o.IncludeCRDsFlag.Set(*boolVal)
} }
case "skip-crds": case "skip-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.SkipCRDsFlag.Set(*boolVal) o.SkipCRDsFlag.Set(*boolVal)
} }
// Handle other flags... // Handle other flags...
} }
} }
func (o *DiffOptions) HandleFlag(name string, value interface{}, changed bool) { func (o *DiffOptions) HandleFlag(name string, value interface{}, changed bool) {
if !changed { if !changed {
return return
} }
switch name { switch name {
case "include-crds": case "include-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.IncludeCRDsFlag.Set(*boolVal) o.IncludeCRDsFlag.Set(*boolVal)
} }
// Handle other flags... // Handle other flags...
} }
} }
func (o *SyncOptions) HandleFlag(name string, value interface{}, changed bool) { func (o *SyncOptions) HandleFlag(name string, value interface{}, changed bool) {
if !changed { if !changed {
return return
} }
switch name { switch name {
case "include-crds": case "include-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.IncludeCRDsFlag.Set(*boolVal) o.IncludeCRDsFlag.Set(*boolVal)
} }
case "skip-crds": case "skip-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.SkipCRDsFlag.Set(*boolVal) o.SkipCRDsFlag.Set(*boolVal)
} }
// Handle other flags... // Handle other flags...
} }
} }
func (o *TemplateOptions) HandleFlag(name string, value interface{}, changed bool) { func (o *TemplateOptions) HandleFlag(name string, value interface{}, changed bool) {
if !changed { if !changed {
return return
} }
switch name { switch name {
case "include-crds": case "include-crds":
if boolVal, ok := value.(*bool); ok { if boolVal, ok := value.(*bool); ok {
o.IncludeCRDsFlag.Set(*boolVal) o.IncludeCRDsFlag.Set(*boolVal)
} }
// Handle other flags... // Handle other flags...
} }
} }

View File

@ -115,20 +115,20 @@ func (t *SyncImpl) Values() []string {
// SkipCRDs returns the skip crds // SkipCRDs returns the skip crds
func (t *SyncImpl) SkipCRDs() bool { func (t *SyncImpl) SkipCRDs() bool {
return t.SyncOptions.SkipCRDsFlag.Value() return t.SyncOptions.SkipCRDsFlag.Value()
} }
// IncludeCRDs returns the include crds // IncludeCRDs returns the include crds
func (t *SyncImpl) IncludeCRDs() bool { func (t *SyncImpl) IncludeCRDs() bool {
return t.SyncOptions.IncludeCRDsFlag.Value() return t.SyncOptions.IncludeCRDsFlag.Value()
} }
// ShouldIncludeCRDs returns true if CRDs should be included // ShouldIncludeCRDs returns true if CRDs should be included
func (t *SyncImpl) ShouldIncludeCRDs() bool { func (t *SyncImpl) ShouldIncludeCRDs() bool {
includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value() includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value()
skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value() skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value()
return includeCRDsExplicit || skipCRDsExplicit return includeCRDsExplicit || skipCRDsExplicit
} }
// Wait returns the wait // Wait returns the wait

View File

@ -24,7 +24,7 @@ type TemplateOptions struct {
Validate bool Validate bool
// SkipCRDsFlag is the skip crds flag // SkipCRDsFlag is the skip crds flag
// Deprecated: Use IncludeCRDsFlag instead // Deprecated: Use IncludeCRDsFlag instead
SkipCRDsFlag common.BoolFlag SkipCRDsFlag common.BoolFlag
// IncludeCRDsFlag is the include crds flag // IncludeCRDsFlag is the include crds flag
IncludeCRDsFlag common.BoolFlag IncludeCRDsFlag common.BoolFlag
// SkipTests is the skip tests flag // SkipTests is the skip tests flag
@ -91,10 +91,10 @@ func (t *TemplateImpl) IncludeCRDs() bool {
// ShouldIncludeCRDs returns whether to include crds // ShouldIncludeCRDs returns whether to include crds
func (t *TemplateImpl) ShouldIncludeCRDs() bool { func (t *TemplateImpl) ShouldIncludeCRDs() bool {
includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value() includeCRDsExplicit := t.IncludeCRDsFlag.WasExplicitlySet() && t.IncludeCRDsFlag.Value()
skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value() skipCRDsExplicit := t.SkipCRDsFlag.WasExplicitlySet() && !t.SkipCRDsFlag.Value()
return includeCRDsExplicit || skipCRDsExplicit return includeCRDsExplicit || skipCRDsExplicit
} }
// NoHooks returns the no hooks // NoHooks returns the no hooks

View File

@ -4,21 +4,20 @@ import "github.com/spf13/cobra"
// ApplyFlagRegistrar handles flags specific to the apply command // ApplyFlagRegistrar handles flags specific to the apply command
type ApplyFlagRegistrar struct { type ApplyFlagRegistrar struct {
*GenericFlagRegistrar *GenericFlagRegistrar
IncludeCRDs bool IncludeCRDs bool
SkipCRDs bool SkipCRDs bool
} }
// NewApplyFlagRegistrar creates a new ApplyFlagRegistrar // NewApplyFlagRegistrar creates a new ApplyFlagRegistrar
func NewApplyFlagRegistrar() *ApplyFlagRegistrar { func NewApplyFlagRegistrar() *ApplyFlagRegistrar {
return &ApplyFlagRegistrar{ return &ApplyFlagRegistrar{
GenericFlagRegistrar: NewGenericFlagRegistrar(), GenericFlagRegistrar: NewGenericFlagRegistrar(),
} }
} }
// RegisterFlags registers apply-specific flags // RegisterFlags registers apply-specific flags
func (r *ApplyFlagRegistrar) RegisterFlags(cmd *cobra.Command) { func (r *ApplyFlagRegistrar) RegisterFlags(cmd *cobra.Command) {
r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing") r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing")
r.RegisterBoolFlag(cmd, "skip-crds", &r.SkipCRDs, false, "if set, no CRDs will be installed on sync. By default, CRDs are installed if not already present") r.RegisterBoolFlag(cmd, "skip-crds", &r.SkipCRDs, false, "if set, no CRDs will be installed on sync. By default, CRDs are installed if not already present")
} }

View File

@ -1,49 +1,49 @@
package flags package flags
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// FlagRegistrar defines an interface for registering and transferring flags // FlagRegistrar defines an interface for registering and transferring flags
type FlagRegistrar interface { type FlagRegistrar interface {
RegisterFlags(cmd *cobra.Command) RegisterFlags(cmd *cobra.Command)
TransferFlags(cmd *cobra.Command, opts interface{}) TransferFlags(cmd *cobra.Command, opts interface{})
} }
// FlagHandler is a generic interface for handling flag values // FlagHandler is a generic interface for handling flag values
type FlagHandler interface { type FlagHandler interface {
// HandleFlag receives a flag name, value, and whether it was changed // HandleFlag receives a flag name, value, and whether it was changed
HandleFlag(name string, value interface{}, changed bool) HandleFlag(name string, value interface{}, changed bool)
} }
// GenericFlagRegistrar is a base struct for flag registrars // GenericFlagRegistrar is a base struct for flag registrars
type GenericFlagRegistrar struct { type GenericFlagRegistrar struct {
// Map of flag names to their values // Map of flag names to their values
values map[string]interface{} values map[string]interface{}
} }
// NewGenericFlagRegistrar creates a new GenericFlagRegistrar // NewGenericFlagRegistrar creates a new GenericFlagRegistrar
func NewGenericFlagRegistrar() *GenericFlagRegistrar { func NewGenericFlagRegistrar() *GenericFlagRegistrar {
return &GenericFlagRegistrar{ return &GenericFlagRegistrar{
values: make(map[string]interface{}), values: make(map[string]interface{}),
} }
} }
// TransferFlags transfers all registered flags to the options // TransferFlags transfers all registered flags to the options
func (r *GenericFlagRegistrar) TransferFlags(cmd *cobra.Command, opts interface{}) { func (r *GenericFlagRegistrar) TransferFlags(cmd *cobra.Command, opts interface{}) {
if handler, ok := opts.(FlagHandler); ok { if handler, ok := opts.(FlagHandler); ok {
flags := cmd.Flags() flags := cmd.Flags()
// Transfer each registered flag // Transfer each registered flag
for name, value := range r.values { for name, value := range r.values {
changed := flags.Changed(name) changed := flags.Changed(name)
handler.HandleFlag(name, value, changed) handler.HandleFlag(name, value, changed)
} }
} }
} }
// RegisterBoolFlag registers a boolean flag and stores its reference // RegisterBoolFlag registers a boolean flag and stores its reference
func (r *GenericFlagRegistrar) RegisterBoolFlag(cmd *cobra.Command, name string, value *bool, defaultValue bool, usage string) { func (r *GenericFlagRegistrar) RegisterBoolFlag(cmd *cobra.Command, name string, value *bool, defaultValue bool, usage string) {
cmd.Flags().BoolVar(value, name, defaultValue, usage) cmd.Flags().BoolVar(value, name, defaultValue, usage)
r.values[name] = value r.values[name] = value
} }

View File

@ -1,140 +1,140 @@
package flags package flags
import ( import (
"testing" "testing"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
// MockFlagHandler implements FlagHandler for testing // MockFlagHandler implements FlagHandler for testing
type MockFlagHandler struct { type MockFlagHandler struct {
handledFlags map[string]interface{} handledFlags map[string]interface{}
changedFlags map[string]bool changedFlags map[string]bool
} }
func NewMockFlagHandler() *MockFlagHandler { func NewMockFlagHandler() *MockFlagHandler {
return &MockFlagHandler{ return &MockFlagHandler{
handledFlags: make(map[string]interface{}), handledFlags: make(map[string]interface{}),
changedFlags: make(map[string]bool), changedFlags: make(map[string]bool),
} }
} }
func (h *MockFlagHandler) HandleFlag(name string, value interface{}, changed bool) { func (h *MockFlagHandler) HandleFlag(name string, value interface{}, changed bool) {
h.handledFlags[name] = value h.handledFlags[name] = value
h.changedFlags[name] = changed h.changedFlags[name] = changed
} }
func TestNewGenericFlagRegistrar(t *testing.T) { func TestNewGenericFlagRegistrar(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
assert.NotNil(t, registrar) assert.NotNil(t, registrar)
assert.NotNil(t, registrar.values) assert.NotNil(t, registrar.values)
assert.Len(t, registrar.values, 0) assert.Len(t, registrar.values, 0)
} }
func TestGenericFlagRegistrar_RegisterBoolFlag(t *testing.T) { func TestGenericFlagRegistrar_RegisterBoolFlag(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
cmd := &cobra.Command{Use: "test"} cmd := &cobra.Command{Use: "test"}
var testFlag bool var testFlag bool
registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag") registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag")
// Verify the flag was registered // Verify the flag was registered
flag := cmd.Flags().Lookup("test-flag") flag := cmd.Flags().Lookup("test-flag")
assert.NotNil(t, flag) assert.NotNil(t, flag)
assert.Equal(t, "test-flag", flag.Name) assert.Equal(t, "test-flag", flag.Name)
assert.Equal(t, "false", flag.DefValue) assert.Equal(t, "false", flag.DefValue)
assert.Equal(t, "Test flag", flag.Usage) assert.Equal(t, "Test flag", flag.Usage)
// Verify the value was stored in the registrar // Verify the value was stored in the registrar
value, exists := registrar.values["test-flag"] value, exists := registrar.values["test-flag"]
assert.True(t, exists) assert.True(t, exists)
assert.Equal(t, &testFlag, value) assert.Equal(t, &testFlag, value)
} }
func TestGenericFlagRegistrar_TransferFlags_NoChanges(t *testing.T) { func TestGenericFlagRegistrar_TransferFlags_NoChanges(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
cmd := &cobra.Command{Use: "test"} cmd := &cobra.Command{Use: "test"}
var testFlag bool var testFlag bool
registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag") registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag")
// Create a mock handler // Create a mock handler
handler := NewMockFlagHandler() handler := NewMockFlagHandler()
// Transfer flags (none changed) // Transfer flags (none changed)
registrar.TransferFlags(cmd, handler) registrar.TransferFlags(cmd, handler)
// Verify the handler was called with the right parameters // Verify the handler was called with the right parameters
assert.Equal(t, &testFlag, handler.handledFlags["test-flag"]) assert.Equal(t, &testFlag, handler.handledFlags["test-flag"])
assert.False(t, handler.changedFlags["test-flag"]) assert.False(t, handler.changedFlags["test-flag"])
} }
func TestGenericFlagRegistrar_TransferFlags_WithChanges(t *testing.T) { func TestGenericFlagRegistrar_TransferFlags_WithChanges(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
cmd := &cobra.Command{Use: "test"} cmd := &cobra.Command{Use: "test"}
var testFlag bool var testFlag bool
registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag") registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag")
// Simulate flag being set on command line // Simulate flag being set on command line
err := cmd.Flags().Set("test-flag", "true") err := cmd.Flags().Set("test-flag", "true")
assert.NoError(t, err) assert.NoError(t, err)
testFlag = true // Value would be updated by cobra testFlag = true // Value would be updated by cobra
// Create a mock handler // Create a mock handler
handler := NewMockFlagHandler() handler := NewMockFlagHandler()
// Transfer flags (with changes) // Transfer flags (with changes)
registrar.TransferFlags(cmd, handler) registrar.TransferFlags(cmd, handler)
// Verify the handler was called with the right parameters // Verify the handler was called with the right parameters
assert.Equal(t, &testFlag, handler.handledFlags["test-flag"]) assert.Equal(t, &testFlag, handler.handledFlags["test-flag"])
assert.True(t, handler.changedFlags["test-flag"]) assert.True(t, handler.changedFlags["test-flag"])
assert.True(t, *handler.handledFlags["test-flag"].(*bool)) assert.True(t, *handler.handledFlags["test-flag"].(*bool))
} }
func TestGenericFlagRegistrar_TransferFlags_NonHandler(t *testing.T) { func TestGenericFlagRegistrar_TransferFlags_NonHandler(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
cmd := &cobra.Command{Use: "test"} cmd := &cobra.Command{Use: "test"}
var testFlag bool var testFlag bool
registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag") registrar.RegisterBoolFlag(cmd, "test-flag", &testFlag, false, "Test flag")
// Use a non-handler type // Use a non-handler type
nonHandler := struct{}{} nonHandler := struct{}{}
// This should not panic // This should not panic
registrar.TransferFlags(cmd, nonHandler) registrar.TransferFlags(cmd, nonHandler)
} }
func TestGenericFlagRegistrar_MultipleFlags(t *testing.T) { func TestGenericFlagRegistrar_MultipleFlags(t *testing.T) {
registrar := NewGenericFlagRegistrar() registrar := NewGenericFlagRegistrar()
cmd := &cobra.Command{Use: "test"} cmd := &cobra.Command{Use: "test"}
var boolFlag bool var boolFlag bool
var boolFlag2 bool var boolFlag2 bool
registrar.RegisterBoolFlag(cmd, "bool-flag", &boolFlag, false, "Boolean flag") registrar.RegisterBoolFlag(cmd, "bool-flag", &boolFlag, false, "Boolean flag")
registrar.RegisterBoolFlag(cmd, "bool-flag2", &boolFlag2, true, "Another boolean flag") registrar.RegisterBoolFlag(cmd, "bool-flag2", &boolFlag2, true, "Another boolean flag")
// Set one flag // Set one flag
err := cmd.Flags().Set("bool-flag", "true") err := cmd.Flags().Set("bool-flag", "true")
assert.NoError(t, err) assert.NoError(t, err)
boolFlag = true // Value would be updated by cobra boolFlag = true // Value would be updated by cobra
// Create a mock handler // Create a mock handler
handler := NewMockFlagHandler() handler := NewMockFlagHandler()
// Transfer flags // Transfer flags
registrar.TransferFlags(cmd, handler) registrar.TransferFlags(cmd, handler)
// Verify both flags were handled correctly // Verify both flags were handled correctly
assert.Equal(t, &boolFlag, handler.handledFlags["bool-flag"]) assert.Equal(t, &boolFlag, handler.handledFlags["bool-flag"])
assert.True(t, handler.changedFlags["bool-flag"]) assert.True(t, handler.changedFlags["bool-flag"])
assert.True(t, *handler.handledFlags["bool-flag"].(*bool)) assert.True(t, *handler.handledFlags["bool-flag"].(*bool))
assert.Equal(t, &boolFlag2, handler.handledFlags["bool-flag2"]) assert.Equal(t, &boolFlag2, handler.handledFlags["bool-flag2"])
assert.False(t, handler.changedFlags["bool-flag2"]) assert.False(t, handler.changedFlags["bool-flag2"])
assert.True(t, *handler.handledFlags["bool-flag2"].(*bool)) // Default is true assert.True(t, *handler.handledFlags["bool-flag2"].(*bool)) // Default is true
} }

View File

@ -4,19 +4,19 @@ import "github.com/spf13/cobra"
// DiffFlagRegistrar handles flags specific to the diff command // DiffFlagRegistrar handles flags specific to the diff command
type DiffFlagRegistrar struct { type DiffFlagRegistrar struct {
*GenericFlagRegistrar *GenericFlagRegistrar
IncludeCRDs bool IncludeCRDs bool
} }
// NewDiffFlagRegistrar creates a new DiffFlagRegistrar // NewDiffFlagRegistrar creates a new DiffFlagRegistrar
func NewDiffFlagRegistrar() *DiffFlagRegistrar { func NewDiffFlagRegistrar() *DiffFlagRegistrar {
return &DiffFlagRegistrar{ return &DiffFlagRegistrar{
GenericFlagRegistrar: NewGenericFlagRegistrar(), GenericFlagRegistrar: NewGenericFlagRegistrar(),
} }
} }
// RegisterFlags registers diff-specific flags // RegisterFlags registers diff-specific flags
func (r *DiffFlagRegistrar) RegisterFlags(cmd *cobra.Command) { func (r *DiffFlagRegistrar) RegisterFlags(cmd *cobra.Command) {
r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing") r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing")
// Diff doesn't have skip-crds // Diff doesn't have skip-crds
} }

View File

@ -1,32 +1,32 @@
package flags package flags
import ( import (
"github.com/helmfile/helmfile/pkg/common" "github.com/helmfile/helmfile/pkg/common"
) )
// BoolFlagInitializer ensures a BoolFlag is initialized with a default value if nil // BoolFlagInitializer ensures a BoolFlag is initialized with a default value if nil
func EnsureBoolFlag(flag *common.BoolFlag, defaultValue bool) { func EnsureBoolFlag(flag *common.BoolFlag, defaultValue bool) {
if *flag == nil { if *flag == nil {
*flag = common.NewBoolFlag(defaultValue) *flag = common.NewBoolFlag(defaultValue)
} }
} }
// StringFlagInitializer ensures a StringFlag is initialized with a default value if nil // StringFlagInitializer ensures a StringFlag is initialized with a default value if nil
func EnsureStringFlag(flag *common.StringFlag, defaultValue string) { func EnsureStringFlag(flag *common.StringFlag, defaultValue string) {
if *flag == nil { if *flag == nil {
*flag = common.NewStringFlag(defaultValue) *flag = common.NewStringFlag(defaultValue)
} }
} }
// StringArrayFlagInitializer ensures a StringArrayFlag is initialized with default values if nil // StringArrayFlagInitializer ensures a StringArrayFlag is initialized with default values if nil
func EnsureStringArrayFlag(flag *common.StringArrayFlag, defaultValues []string) { func EnsureStringArrayFlag(flag *common.StringArrayFlag, defaultValues []string) {
if *flag == nil { if *flag == nil {
*flag = common.NewStringArrayFlag(defaultValues) *flag = common.NewStringArrayFlag(defaultValues)
} }
} }
// InitializeOptions initializes all nil flag fields in an options struct // InitializeOptions initializes all nil flag fields in an options struct
func InitializeOptions(options interface{}) { func InitializeOptions(options interface{}) {
// This could be expanded to use reflection to automatically find and initialize // This could be expanded to use reflection to automatically find and initialize
// all flag fields in any options struct // all flag fields in any options struct
} }

View File

@ -4,21 +4,20 @@ import "github.com/spf13/cobra"
// SyncFlagRegistrar handles flags specific to the sync command // SyncFlagRegistrar handles flags specific to the sync command
type SyncFlagRegistrar struct { type SyncFlagRegistrar struct {
*GenericFlagRegistrar *GenericFlagRegistrar
IncludeCRDs bool IncludeCRDs bool
SkipCRDs bool SkipCRDs bool
} }
// NewSyncFlagRegistrar creates a new SyncFlagRegistrar // NewSyncFlagRegistrar creates a new SyncFlagRegistrar
func NewSyncFlagRegistrar() *SyncFlagRegistrar { func NewSyncFlagRegistrar() *SyncFlagRegistrar {
return &SyncFlagRegistrar{ return &SyncFlagRegistrar{
GenericFlagRegistrar: NewGenericFlagRegistrar(), GenericFlagRegistrar: NewGenericFlagRegistrar(),
} }
} }
// RegisterFlags registers sync-specific flags // RegisterFlags registers sync-specific flags
func (r *SyncFlagRegistrar) RegisterFlags(cmd *cobra.Command) { func (r *SyncFlagRegistrar) RegisterFlags(cmd *cobra.Command) {
r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing") r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing")
r.RegisterBoolFlag(cmd, "skip-crds", &r.SkipCRDs, false, "if set, no CRDs will be installed on sync. By default, CRDs are installed if not already present") r.RegisterBoolFlag(cmd, "skip-crds", &r.SkipCRDs, false, "if set, no CRDs will be installed on sync. By default, CRDs are installed if not already present")
} }

View File

@ -4,19 +4,18 @@ import "github.com/spf13/cobra"
// TemplateFlagRegistrar handles flags specific to the template command // TemplateFlagRegistrar handles flags specific to the template command
type TemplateFlagRegistrar struct { type TemplateFlagRegistrar struct {
*GenericFlagRegistrar *GenericFlagRegistrar
IncludeCRDs bool IncludeCRDs bool
} }
// NewTemplateFlagRegistrar creates a new TemplateFlagRegistrar // NewTemplateFlagRegistrar creates a new TemplateFlagRegistrar
func NewTemplateFlagRegistrar() *TemplateFlagRegistrar { func NewTemplateFlagRegistrar() *TemplateFlagRegistrar {
return &TemplateFlagRegistrar{ return &TemplateFlagRegistrar{
GenericFlagRegistrar: NewGenericFlagRegistrar(), GenericFlagRegistrar: NewGenericFlagRegistrar(),
} }
} }
// RegisterFlags registers template-specific flags // RegisterFlags registers template-specific flags
func (r *TemplateFlagRegistrar) RegisterFlags(cmd *cobra.Command) { func (r *TemplateFlagRegistrar) RegisterFlags(cmd *cobra.Command) {
r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing") r.RegisterBoolFlag(cmd, "include-crds", &r.IncludeCRDs, false, "include CRDs in the diffing")
} }

View File

@ -2036,7 +2036,7 @@ type DiffOpts struct {
// If this is true, Color has no effect. // If this is true, Color has no effect.
NoColor bool NoColor bool
Set []string Set []string
IncludeCRDs bool IncludeCRDs bool
SkipCleanup bool SkipCleanup bool
SkipDiffOnInstall bool SkipDiffOnInstall bool
DiffArgs string DiffArgs string

View File

@ -389,26 +389,26 @@ func execHelm(t *testing.T, args ...string) string {
func waitForRegistry(t *testing.T, address string, timeout time.Duration) error { func waitForRegistry(t *testing.T, address string, timeout time.Duration) error {
t.Helper() t.Helper()
client := http.Client{ client := http.Client{
Timeout: 1 * time.Second, Timeout: 1 * time.Second,
} }
url := fmt.Sprintf("http://%s/v2/", address) url := fmt.Sprintf("http://%s/v2/", address)
deadline := time.Now().Add(timeout) deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) { for time.Now().Before(deadline) {
resp, err := client.Get(url) resp, err := client.Get(url)
if err == nil { if err == nil {
resp.Body.Close() resp.Body.Close()
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusUnauthorized { if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusUnauthorized {
// Registry is up - a 200 OK or 401 Unauthorized both indicate the registry is running // Registry is up - a 200 OK or 401 Unauthorized both indicate the registry is running
return nil return nil
} }
} }
// Wait a bit before trying again // Wait a bit before trying again
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
} }
return fmt.Errorf("timed out waiting for registry at %s after %s", address, timeout) return fmt.Errorf("timed out waiting for registry at %s after %s", address, timeout)
} }