GetInputValue gets the first arg. Also parses the special input hashtag flag that deals with the situation "buf build -#format=json". The existence of 0 or 1 args should be handled by the Args field on Command.
( container app.ArgContainer, inputHashtag string, defaultValue string, )
| 265 | // Also parses the special input hashtag flag that deals with the situation "buf build -#format=json". |
| 266 | // The existence of 0 or 1 args should be handled by the Args field on Command. |
| 267 | func GetInputValue( |
| 268 | container app.ArgContainer, |
| 269 | inputHashtag string, |
| 270 | defaultValue string, |
| 271 | ) (string, error) { |
| 272 | var arg string |
| 273 | switch numArgs := container.NumArgs(); numArgs { |
| 274 | case 0: |
| 275 | if inputHashtag != "" { |
| 276 | arg = "-#" + inputHashtag |
| 277 | } |
| 278 | case 1: |
| 279 | arg = container.Arg(0) |
| 280 | if arg == "" { |
| 281 | return "", errors.New("first argument is present but empty") |
| 282 | } |
| 283 | // if arg is non-empty and inputHashtag is non-empty, this means two arguments were specified |
| 284 | if inputHashtag != "" { |
| 285 | return "", errors.New("only 1 argument allowed but 2 arguments specified") |
| 286 | } |
| 287 | default: |
| 288 | return "", fmt.Errorf("only 1 argument allowed but %d arguments specified", numArgs) |
| 289 | } |
| 290 | if arg != "" { |
| 291 | return arg, nil |
| 292 | } |
| 293 | return defaultValue, nil |
| 294 | } |
| 295 | |
| 296 | // VisibilityFlagToVisibilityAllowUnspecified parses the given string as a modulev1.ModuleVisibility |
| 297 | // where an empty string will be parsed as unspecified |
no outgoing calls
no test coverage detected
searching dependent graphs…