github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/cmdflag/flag.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package cmdflag handles flag processing common to several go tools. 6 package cmdflag 7 8 import ( 9 "github.com/shogo82148/std/errors" 10 "github.com/shogo82148/std/flag" 11 ) 12 13 // ErrFlagTerminator indicates the distinguished token "--", which causes the 14 // flag package to treat all subsequent arguments as non-flags. 15 var ErrFlagTerminator = errors.New("flag terminator") 16 17 // A FlagNotDefinedError indicates a flag-like argument that does not correspond 18 // to any registered flag in a FlagSet. 19 type FlagNotDefinedError struct { 20 RawArg string 21 Name string 22 HasValue bool 23 Value string 24 } 25 26 func (e FlagNotDefinedError) Error() string 27 28 // A NonFlagError indicates an argument that is not a syntactically-valid flag. 29 type NonFlagError struct { 30 RawArg string 31 } 32 33 func (e NonFlagError) Error() string 34 35 // ParseOne sees if args[0] is present in the given flag set and if so, 36 // sets its value and returns the flag along with the remaining (unused) arguments. 37 // 38 // ParseOne always returns either a non-nil Flag or a non-nil error, 39 // and always consumes at least one argument (even on error). 40 // 41 // Unlike (*flag.FlagSet).Parse, ParseOne does not log its own errors. 42 func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []string, err error)