MCPcopy Create free account
hub / github.com/alibaba/open-code-review / positionalSignature

Function positionalSignature

cmd/opencodereview/arg_errors.go:81–94  ·  view source on GitHub ↗

positionalSignature extracts the positional-argument part of cmd.Use, e.g. " " from "set " and " " from "rule [flags] ". Bracketed fields are not placeholders the user types, so "[flags]" and inline enumerations such as "[bash|zsh]" are dropped; enumerated v

(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

79// types, so "[flags]" and inline enumerations such as "[bash|zsh]" are dropped;
80// enumerated values are reported from ValidArgs instead.
81func positionalSignature(cmd *cobra.Command) string {
82 fields := strings.Fields(cmd.Use)
83 if len(fields) < 2 {
84 return ""
85 }
86
87 parts := make([]string, 0, len(fields)-1)
88 for _, f := range fields[1:] {
89 if strings.HasPrefix(f, "<") {
90 parts = append(parts, f)
91 }
92 }
93 return strings.Join(parts, " ")
94}
95
96// validArgNames strips the "name\tdescription" form Cobra allows in ValidArgs,
97// keeping only the value the user is expected to type. The split matches the one

Callers 3

TestPositionalSignatureFunction · 0.85
argCountErrorFunction · 0.85

Calls

no outgoing calls