mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Merge pull request #32944 from k82cn/refactor_builder_visitorResult
Automatic merge from submit-queue Refactor Builder.visitorResult by extra methonds. **What this PR does / why we need it**: Code polish; it'll make code readable.
This commit is contained in:
commit
4b700f41ec
@ -540,6 +540,31 @@ func (b *Builder) visitorResult() *Result {
|
|||||||
|
|
||||||
// visit selectors
|
// visit selectors
|
||||||
if b.selector != nil {
|
if b.selector != nil {
|
||||||
|
return b.visitBySelector()
|
||||||
|
}
|
||||||
|
|
||||||
|
// visit items specified by resource and name
|
||||||
|
if len(b.resourceTuples) != 0 {
|
||||||
|
return b.visitByResource()
|
||||||
|
}
|
||||||
|
|
||||||
|
// visit items specified by name
|
||||||
|
if len(b.names) != 0 {
|
||||||
|
return b.visitByName()
|
||||||
|
}
|
||||||
|
|
||||||
|
// visit items specified by paths
|
||||||
|
if len(b.paths) != 0 {
|
||||||
|
return b.visitByPaths()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.resources) != 0 {
|
||||||
|
return &Result{err: fmt.Errorf("resource(s) were provided, but no name, label selector, or --all flag specified")}
|
||||||
|
}
|
||||||
|
return &Result{err: missingResourceError}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Builder) visitBySelector() *Result {
|
||||||
if len(b.names) != 0 {
|
if len(b.names) != 0 {
|
||||||
return &Result{err: fmt.Errorf("name cannot be provided when a selector is specified")}
|
return &Result{err: fmt.Errorf("name cannot be provided when a selector is specified")}
|
||||||
}
|
}
|
||||||
@ -578,10 +603,9 @@ func (b *Builder) visitorResult() *Result {
|
|||||||
return &Result{visitor: EagerVisitorList(visitors), sources: visitors}
|
return &Result{visitor: EagerVisitorList(visitors), sources: visitors}
|
||||||
}
|
}
|
||||||
return &Result{visitor: VisitorList(visitors), sources: visitors}
|
return &Result{visitor: VisitorList(visitors), sources: visitors}
|
||||||
}
|
}
|
||||||
|
|
||||||
// visit items specified by resource and name
|
func (b *Builder) visitByResource() *Result {
|
||||||
if len(b.resourceTuples) != 0 {
|
|
||||||
// if b.singular is false, this could be by default, so double-check length
|
// if b.singular is false, this could be by default, so double-check length
|
||||||
// of resourceTuples to determine if in fact it is singular or not
|
// of resourceTuples to determine if in fact it is singular or not
|
||||||
isSingular := b.singular
|
isSingular := b.singular
|
||||||
@ -646,10 +670,9 @@ func (b *Builder) visitorResult() *Result {
|
|||||||
visitors = VisitorList(items)
|
visitors = VisitorList(items)
|
||||||
}
|
}
|
||||||
return &Result{singular: isSingular, visitor: visitors, sources: items}
|
return &Result{singular: isSingular, visitor: visitors, sources: items}
|
||||||
}
|
}
|
||||||
|
|
||||||
// visit items specified by name
|
func (b *Builder) visitByName() *Result {
|
||||||
if len(b.names) != 0 {
|
|
||||||
isSingular := len(b.names) == 1
|
isSingular := len(b.names) == 1
|
||||||
|
|
||||||
if len(b.paths) != 0 {
|
if len(b.paths) != 0 {
|
||||||
@ -688,10 +711,9 @@ func (b *Builder) visitorResult() *Result {
|
|||||||
visitors = append(visitors, info)
|
visitors = append(visitors, info)
|
||||||
}
|
}
|
||||||
return &Result{singular: isSingular, visitor: VisitorList(visitors), sources: visitors}
|
return &Result{singular: isSingular, visitor: VisitorList(visitors), sources: visitors}
|
||||||
}
|
}
|
||||||
|
|
||||||
// visit items specified by paths
|
func (b *Builder) visitByPaths() *Result {
|
||||||
if len(b.paths) != 0 {
|
|
||||||
singular := !b.dir && !b.stream && len(b.paths) == 1
|
singular := !b.dir && !b.stream && len(b.paths) == 1
|
||||||
if len(b.resources) != 0 {
|
if len(b.resources) != 0 {
|
||||||
return &Result{singular: singular, err: fmt.Errorf("when paths, URLs, or stdin is provided as input, you may not specify resource arguments as well")}
|
return &Result{singular: singular, err: fmt.Errorf("when paths, URLs, or stdin is provided as input, you may not specify resource arguments as well")}
|
||||||
@ -717,12 +739,6 @@ func (b *Builder) visitorResult() *Result {
|
|||||||
visitors = NewDecoratedVisitor(visitors, RetrieveLatest)
|
visitors = NewDecoratedVisitor(visitors, RetrieveLatest)
|
||||||
}
|
}
|
||||||
return &Result{singular: singular, visitor: visitors, sources: b.paths}
|
return &Result{singular: singular, visitor: visitors, sources: b.paths}
|
||||||
}
|
|
||||||
|
|
||||||
if len(b.resources) != 0 {
|
|
||||||
return &Result{err: fmt.Errorf("resource(s) were provided, but no name, label selector, or --all flag specified")}
|
|
||||||
}
|
|
||||||
return &Result{err: missingResourceError}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do returns a Result object with a Visitor for the resources identified by the Builder.
|
// Do returns a Result object with a Visitor for the resources identified by the Builder.
|
||||||
|
Loading…
Reference in New Issue
Block a user