MCPcopy
hub / github.com/urfave/cli / String

Method String

flag_bool_with_inverse.go:173–208  ·  view source on GitHub ↗

String implements the standard Stringer interface. Example for BoolFlag{Name: "env"} --[no-]env (default: false) Example for BoolFlag{Name: "env", Aliases: []string{"e"}} --[no-]env, -e (default: false)

()

Source from the content-addressed store, hash-verified

171// Example for BoolFlag{Name: "env", Aliases: []string{"e"}}
172// --[no-]env, -e (default: false)
173func (bif *BoolWithInverseFlag) String() string {
174 out := FlagStringer(bif)
175
176 i := strings.Index(out, "\t")
177
178 prefix := "--"
179
180 // single character flags are prefixed with `-` instead of `--`
181 if len(bif.Name) == 1 {
182 prefix = "-"
183 }
184
185 // Guard against a FlagStringer that returns a string without a tab (e.g.
186 // a custom stringer or the default stringer when the flag does not
187 // implement DocGenerationFlag). In that case treat the entire output as
188 // the tab-delimited suffix so the slice never goes out of bounds.
189 if i < 0 {
190 i = 0
191 }
192
193 var aliasParts []string
194 for _, alias := range bif.Aliases {
195 aPrefix := "--"
196 if len(alias) == 1 {
197 aPrefix = "-"
198 }
199 aliasParts = append(aliasParts, aPrefix+alias)
200 }
201
202 names := fmt.Sprintf("%s[%s]%s", prefix, bif.inversePrefix(), bif.Name)
203 if len(aliasParts) > 0 {
204 names = names + ", " + strings.Join(aliasParts, ", ")
205 }
206
207 return fmt.Sprintf("%s%s", names, out[i:])
208}
209
210// IsBoolFlag returns whether the flag doesn't need to accept args
211func (bif *BoolWithInverseFlag) IsBoolFlag() bool {

Calls 1

inversePrefixMethod · 0.95