-
Notifications
You must be signed in to change notification settings - Fork 552
/
args.go
29 lines (25 loc) · 825 Bytes
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2020 Vectorized, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
package cli
import (
"fmt"
"github.com/spf13/cobra"
)
// Wrapping cobra's matchAll function and return an error including usage String.
// MatchAll allows combining several PositionalArgs to work in concert.
func MatchAll(checks ...cobra.PositionalArgs) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
for _, check := range checks {
if err := check(cmd, args); err != nil {
return fmt.Errorf("%v\n\n%v", err, cmd.UsageString())
}
}
return nil
}
}