-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargument.go
44 lines (34 loc) · 899 Bytes
/
argument.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cli
import (
"fmt"
"github.com/bobg/errors"
"github.com/broothie/option"
"github.com/samber/lo"
)
type Argument struct {
name string
description string
parser argParser
value any
}
func newArgument(name, description string, options ...option.Option[*Argument]) (*Argument, error) {
baseArgument := &Argument{
name: name,
description: description,
parser: NewArgParser(StringParser),
}
argument, err := option.Apply(baseArgument, options...)
if err != nil {
return nil, errors.Wrapf(err, "building argument %q", name)
}
return argument, nil
}
func (a *Argument) inBrackets() string {
return fmt.Sprintf("<%s>", a.name)
}
func (c *Command) findArg(name string) (*Argument, bool) {
if arg, found := lo.Find(c.arguments, func(argument *Argument) bool { return argument.name == name }); found {
return arg, true
}
return nil, false
}