Add focused CLI argument helpers
This commit is contained in:
@@ -82,3 +82,22 @@ func rejectExtraArgs(stderr io.Writer, command string, args []string) bool {
|
||||
fmt.Fprintf(stderr, "%s: %s does not accept arguments: %s\n", app.Name, command, strings.Join(args, " "))
|
||||
return true
|
||||
}
|
||||
|
||||
func parseOptionalPathArg(stderr io.Writer, command string, args []string) (string, bool) {
|
||||
if len(args) > 1 {
|
||||
fmt.Fprintf(stderr, "%s: %s accepts at most one path\n", app.Name, command)
|
||||
return "", false
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return "", true
|
||||
}
|
||||
return args[0], true
|
||||
}
|
||||
|
||||
func rejectPositionalArgs(stderr io.Writer, command string, args []string) bool {
|
||||
if len(args) == 0 {
|
||||
return false
|
||||
}
|
||||
fmt.Fprintf(stderr, "%s: %s does not accept positional arguments: %v\n", app.Name, command, args)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user