MCPcopy Create free account
hub / github.com/bufbuild/buf / GetInputValue

Function GetInputValue

private/buf/bufcli/flags_args.go:267–294  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
267func 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

Callers 14

runFunction · 0.92
getBuildableWorkspaceFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92
runFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…