Install command batches through one path
This commit is contained in:
13
command.go
13
command.go
@@ -263,12 +263,16 @@ func captureComposition(record *commandRecord) {
|
||||
}
|
||||
|
||||
func validateCommandDeclaration(command Command) error {
|
||||
return validateCommandPlacement(command)
|
||||
}
|
||||
|
||||
func validateCommandPlacement(command Command) error {
|
||||
var issues []error
|
||||
collectDeclarationIssues(command, nil, &issues)
|
||||
collectDeclarationIssues(command, nil, true, &issues)
|
||||
return errors.Join(issues...)
|
||||
}
|
||||
|
||||
func collectDeclarationIssues(command Command, parents []string, issues *[]error) {
|
||||
func collectDeclarationIssues(command Command, parents []string, root bool, issues *[]error) {
|
||||
if command.record == nil {
|
||||
*issues = append(*issues, errors.New("invalid zero command declaration"))
|
||||
return
|
||||
@@ -283,6 +287,9 @@ func collectDeclarationIssues(command Command, parents []string, issues *[]error
|
||||
*issues = append(*issues, issue)
|
||||
}
|
||||
}
|
||||
if record.rootOnly && !root {
|
||||
*issues = append(*issues, fmt.Errorf("root-only command %q is nested beneath another command", label))
|
||||
}
|
||||
if record.invalid || record.absent {
|
||||
return
|
||||
}
|
||||
@@ -290,7 +297,7 @@ func collectDeclarationIssues(command Command, parents []string, issues *[]error
|
||||
if child.record == nil {
|
||||
continue
|
||||
}
|
||||
collectDeclarationIssues(child, path, issues)
|
||||
collectDeclarationIssues(child, path, false, issues)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user