| 1 | package getoptscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.16 bytes/" |
| 5 | "flagscip-go gomod github.com/golang/go/src go1.16 flag/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 7 | "ioscip-go gomod github.com/golang/go/src go1.16 io/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.16 os/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 10 | "unicode/utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/" |
| 11 | ) |
| 12 | |
| 13 | const ( |
| 14 | typeBoolscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeBool. = iota |
| 15 | typeStringscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeString. |
| 16 | typeIntscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeInt. |
| 17 | typeUintscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeUint. |
| 18 | typeInt64scip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeInt64. |
| 19 | typeUint64scip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeUint64. |
| 20 | typeFloat64scip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeFloat64. |
| 21 | typeDurationscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/typeDuration. |
| 22 | ) |
| 23 | |
| 24 | // A Flag represents the state of a flag. |
| 25 | type Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag# struct { |
| 26 | Namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Name. string |
| 27 | Runescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Rune. rune |
| 28 | Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Value. flagscip-go gomod github.com/golang/go/src go1.16 flag/.Valuescip-go gomod github.com/golang/go/src go1.16 flag/Value# |
| 29 | Usagescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Usage. string |
| 30 | usedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#used. bool |
| 31 | } |
| 32 | |
| 33 | // A FlagSet represents a set of defined flags. The zero value of a |
| 34 | // FlagSet has no name and has ContinueOnError error handling. |
| 35 | type FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet# struct { |
| 36 | parsedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#parsed. bool |
| 37 | optindexscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#optindex. int |
| 38 | |
| 39 | flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags. map[rune]*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag# |
| 40 | outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output. ioscip-go gomod github.com/golang/go/src go1.16 io/.Writerscip-go gomod github.com/golang/go/src go1.16 io/Writer# |
| 41 | |
| 42 | namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#name. string |
| 43 | errorHandlingscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#errorHandling. flagscip-go gomod github.com/golang/go/src go1.16 flag/.ErrorHandlingscip-go gomod github.com/golang/go/src go1.16 flag/ErrorHandling# |
| 44 | |
| 45 | Usagescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Usage. func() |
| 46 | } |
| 47 | |
| 48 | // NewFlagSet returns a new, empty flag set. |
| 49 | func NewFlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/NewFlagSet().(name string, err flagscip-go gomod github.com/golang/go/src go1.16 flag/.ErrorHandlingscip-go gomod github.com/golang/go/src go1.16 flag/ErrorHandling#) *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet# { |
| 50 | set := FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#{ |
| 51 | namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#name.: name, |
| 52 | flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.: make(map[rune]*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#), |
| 53 | outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output.: osscip-go gomod github.com/golang/go/src go1.16 os/.Stderrscip-go gomod github.com/golang/go/src go1.16 os/Stderr., |
| 54 | errorHandlingscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#errorHandling.: err, |
| 55 | } |
| 56 | set.Usagescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Usage. = func() { |
| 57 | if set.namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#name. != "" { |
| 58 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output., "Usage of %s:\n\n", set.namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#name.) |
| 59 | } else { |
| 60 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output., "Usage:\n\n") |
| 61 | } |
| 62 | set.PrintDefaultsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#PrintDefaults().() |
| 63 | } |
| 64 | return &set |
| 65 | } |
| 66 | |
| 67 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) parsescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#parse().(args []string) error { |
| 68 | var buf bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.16 bytes/Buffer# |
| 69 | for r, f := range set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags. { |
| 70 | buf.WriteRunescip-go gomod github.com/golang/go/src go1.16 bytes/Buffer#WriteRune().(r) |
| 71 | if f, ok := f.Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Value..(boolFlagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/boolFlag#); !ok || !f.IsBoolFlagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/boolFlag#IsBoolFlag.() { |
| 72 | buf.WriteBytescip-go gomod github.com/golang/go/src go1.16 bytes/Buffer#WriteByte().(':') |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | options, optind, err := Getoptsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Getopts().(args, buf.Stringscip-go gomod github.com/golang/go/src go1.16 bytes/Buffer#String().()) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | set.optindexscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#optindex. = optind |
| 81 | |
| 82 | for _, opt := range options { |
| 83 | err = set.Setscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Set().(fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%c", opt.Optionscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Option#Option.), opt.Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Option#Value.) |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | set.parsedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#parsed. = true |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | // Set sets the value of the named flag. |
| 94 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Setscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Set().(name, value string) error { |
| 95 | r, _ := utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/DecodeRuneInString().(name) |
| 96 | flag, ok := set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.[r] |
| 97 | if !ok { |
| 98 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("no such flag -%v", name) |
| 99 | } |
| 100 | |
| 101 | flag.usedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#used. = true |
| 102 | return flag.Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Value..Setscip-go gomod github.com/golang/go/src go1.16 flag/Value#Set().(value) |
| 103 | } |
| 104 | |
| 105 | // Arg returns the i'th command-line argument. Arg(0) is the first |
| 106 | // remaining argument after flags have been processed. Arg returns an |
| 107 | // empty string if the requested element does not exist. |
| 108 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Argscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Arg().(i int) string { |
| 109 | var arg string |
| 110 | if len(set.Argsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Args().()) < i { |
| 111 | arg = set.Argsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Args().()[i] |
| 112 | } |
| 113 | return arg |
| 114 | } |
| 115 | |
| 116 | // Args returns the non-flag command-line arguments. |
| 117 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Argsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Args().() []string { |
| 118 | return osscip-go gomod github.com/golang/go/src go1.16 os/.Argsscip-go gomod github.com/golang/go/src go1.16 os/Args.[set.optindexscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#optindex.:] |
| 119 | } |
| 120 | |
| 121 | // NArg is the number of arguments remaining after flags have been |
| 122 | // processed. |
| 123 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) NArgscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#NArg().() int { |
| 124 | return len(set.Argsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Args().()) |
| 125 | } |
| 126 | |
| 127 | // NFlag returns the number of command-line flags that have been set. |
| 128 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) NFlagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#NFlag().() int { |
| 129 | return len(set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.) |
| 130 | } |
| 131 | |
| 132 | // Parsed reports whether the command-line flags have been parsed. |
| 133 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Parsedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Parsed().() bool { |
| 134 | return set.parsedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#parsed. |
| 135 | } |
| 136 | |
| 137 | // ParseSlice parses the command-line flags from args. Must be called |
| 138 | // after all flags are defined and before flags are accessed by the |
| 139 | // program. |
| 140 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) ParseSlicescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#ParseSlice().(args []string) (err error) { |
| 141 | err = set.parsescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#parse().(args) |
| 142 | if err != nil { |
| 143 | switch set.errorHandlingscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#errorHandling. { |
| 144 | case flagscip-go gomod github.com/golang/go/src go1.16 flag/.PanicOnErrorscip-go gomod github.com/golang/go/src go1.16 flag/PanicOnError.: |
| 145 | panic(err) |
| 146 | case flagscip-go gomod github.com/golang/go/src go1.16 flag/.ExitOnErrorscip-go gomod github.com/golang/go/src go1.16 flag/ExitOnError.: |
| 147 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.16 fmt/Println().(err) |
| 148 | osscip-go gomod github.com/golang/go/src go1.16 os/.Exitscip-go gomod github.com/golang/go/src go1.16 os/Exit().(2) |
| 149 | } |
| 150 | } |
| 151 | return |
| 152 | } |
| 153 | |
| 154 | // Parse parses the command-line flags from os.Args. Must be called |
| 155 | // after all flags are defined and before flags are accessed by the |
| 156 | // program. |
| 157 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Parsescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Parse().() error { |
| 158 | return set.ParseSlicescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#ParseSlice().(osscip-go gomod github.com/golang/go/src go1.16 os/.Argsscip-go gomod github.com/golang/go/src go1.16 os/Args.) |
| 159 | } |
| 160 | |
| 161 | // ErrorHandling returns the error handling behavior of the flag set. |
| 162 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) ErrorHandlingscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#ErrorHandling().() flagscip-go gomod github.com/golang/go/src go1.16 flag/.ErrorHandlingscip-go gomod github.com/golang/go/src go1.16 flag/ErrorHandling# { |
| 163 | return set.errorHandlingscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#errorHandling. |
| 164 | } |
| 165 | |
| 166 | // Var defines a flag with the specified name and usage string. The type |
| 167 | // and value of the flag are represented by the first argument, of type |
| 168 | // Value, which typically holds a user-defined implementation of Value. |
| 169 | // For instance, the caller could create a flag that turns a |
| 170 | // comma-separated string into a slice of strings by giving the slice |
| 171 | // the methods of Value; in particular, Set would decompose the |
| 172 | // comma-separated string into the slice. |
| 173 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Varscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Var().(value flagscip-go gomod github.com/golang/go/src go1.16 flag/.Valuescip-go gomod github.com/golang/go/src go1.16 flag/Value#, name string, usage string) { |
| 174 | r, _ := utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/DecodeRuneInString().(name) |
| 175 | set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.[r] = &Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#{ |
| 176 | Namescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Name.: name, |
| 177 | Runescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Rune.: r, |
| 178 | Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Value.: value, |
| 179 | Usagescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Usage.: usage, |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) visitIfscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#visitIf().(cond func(*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#) bool, fn func(*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#)) { |
| 184 | var runes []rune |
| 185 | for r := range set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags. { |
| 186 | runes = append(runes, r) |
| 187 | } |
| 188 | |
| 189 | for i := range runes { |
| 190 | for j := i; j > 0; j-- { |
| 191 | if runes[j] < runes[j-1] { |
| 192 | runes[j], runes[j-1] = runes[j-1], runes[j] |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | for _, r := range runes { |
| 198 | if cond == nil || cond(set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.[r]) { |
| 199 | fn(set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.[r]) |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // VisitAll visits the command-line flags in lexicographical order, |
| 205 | // calling fn for each. It visits all flags, even those not set. |
| 206 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) VisitAllscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#VisitAll().(fn func(*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#)) { |
| 207 | set.visitIfscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#visitIf().(nil, fn) |
| 208 | } |
| 209 | |
| 210 | // Visit visits the command-line flags in lexicographical order, |
| 211 | // calling fn for each. |
| 212 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Visitscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Visit().(fn func(*Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#)) { |
| 213 | set.visitIfscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#visitIf().(func(flag *Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#) bool { return flag.usedscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#used. }, fn) |
| 214 | } |
| 215 | |
| 216 | // Lookup returns the Flag structure of the named flag, returning nil if |
| 217 | // none exists. |
| 218 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Lookupscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Lookup().(name string) *Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag# { |
| 219 | r, _ := utf8scip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.16 `unicode/utf8`/DecodeRuneInString().(name) |
| 220 | return set.flagsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#flags.[r] |
| 221 | } |
| 222 | |
| 223 | // PrintDefaults prints, to standard error unless configured otherwise, |
| 224 | // a usage message showing the default settings of all defined |
| 225 | // command-line flags. |
| 226 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) PrintDefaultsscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#PrintDefaults().() { |
| 227 | out := set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output. |
| 228 | set.VisitAllscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#VisitAll().(func(flag *Flagscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#) { |
| 229 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(out, " -%c", flag.Runescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Rune.) |
| 230 | |
| 231 | val := flag.Valuescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Value. |
| 232 | |
| 233 | usage := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(flag.Usagescip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/Flag#Usage., "\n", "\n \t", -1) |
| 234 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(out, "\t%s", usage) |
| 235 | |
| 236 | if _, ok := val.(*stringValscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/stringVal#); ok { |
| 237 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(out, " (default %q)", val) |
| 238 | } else if _, ok := val.(*boolValscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/boolVal#); !ok { |
| 239 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(out, " (default %s)", val) |
| 240 | } |
| 241 | fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Fprintf().(out, "\n") |
| 242 | }) |
| 243 | } |
| 244 | |
| 245 | // SetOutput sets the destination for usage and error messages. If |
| 246 | // output is nil, os.Stderr is used. |
| 247 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) SetOutputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#SetOutput().(output ioscip-go gomod github.com/golang/go/src go1.16 io/.Writerscip-go gomod github.com/golang/go/src go1.16 io/Writer#) { |
| 248 | if output == nil { |
| 249 | set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output. = osscip-go gomod github.com/golang/go/src go1.16 os/.Stderrscip-go gomod github.com/golang/go/src go1.16 os/Stderr. |
| 250 | } else { |
| 251 | set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output. = output |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Output returns the destination for usage and error messages. |
| 256 | // os.Stderr is returned if output was not set or was set to nil. |
| 257 | func (set *FlagSetscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#) Outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#Output().() ioscip-go gomod github.com/golang/go/src go1.16 io/.Writerscip-go gomod github.com/golang/go/src go1.16 io/Writer# { |
| 258 | return set.outputscip-go gomod git.sr.ht/~sircmpwn/getopt . `git.sr.ht/~sircmpwn/getopt`/FlagSet#output. |
| 259 | } |