Add shared command path primitives

This commit is contained in:
2026-10-19 15:08:00 +00:00
parent d7cc12a347
commit b3fb795224
5 changed files with 207 additions and 30 deletions

View File

@@ -3,10 +3,10 @@ package commandkit
import (
"errors"
"fmt"
"strings"
"unicode"
commandmeta "gitea.maximumdirect.net/eric/CommandKit/internal/commandmeta"
"gitea.maximumdirect.net/eric/CommandKit/internal/commandpath"
)
// Command is an opaque, reusable declaration captured by NewCommand, Group,
@@ -297,7 +297,7 @@ func collectDeclarationIssues(command Command, parents []string, root bool, issu
}
record := command.record
path := append(append([]string(nil), parents...), record.name)
label := strings.Join(path, " ")
label := commandpath.FromTokens(path).String()
for _, issue := range record.issues {
if label != "" {
*issues = append(*issues, fmt.Errorf("command %q: %w", label, issue))
@@ -320,11 +320,7 @@ func collectDeclarationIssues(command Command, parents []string, root bool, issu
}
func validateCommandName(name string) error {
fields := strings.Fields(name)
if len(fields) != 1 || fields[0] != name || strings.HasPrefix(name, "-") || name == "--" {
return fmt.Errorf("command name %q must be one non-option token", name)
}
return nil
return commandpath.ValidateComponent(name)
}
func validateBindings[I any](flags []Flag[I], arguments []Argument[I]) error {