Skip to content
Myr

Use pflag.ShorthandLookup

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 8f0203b · Browse files · 1 file+13 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−12 removed

  • other:+13 added−12 removed

1 file+13 added−12 removed

modified:command.go+13 added-12 removed
9 unmodified lines
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314//Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.15//In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.14// Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.15// In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.16package cobra1718import (19 "bytes"
348 unmodified lines
368369{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`370}371372func hasNoOptDefVal(name string, f *flag.FlagSet) bool {373 flag := f.Lookup(name)372func hasNoOptDefVal(name string, fs *flag.FlagSet) bool {373 flag := fs.Lookup(name)374 if flag == nil {375 return false376 }377 return flag.NoOptDefVal != ""378}379380func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool {381 result := false382 fs.VisitAll(func(flag *flag.Flag) {383 if flag.Shorthand == name && flag.NoOptDefVal != "" {384 result = true385 return386 }387 })388 return result381 if len(name) == 0 {382 return false383 }384385 flag := fs.ShorthandLookup(name[:1])386 if flag == nil {387 return false388 }389 return flag.NoOptDefVal != ""390}391392func stripFlags(args []string, c *Command) []string {393 if len(args) == 0 {
868 unmodified lines