Repository navigation
Expand file tree
/
Copy pathcommand-requirement_values.go
More file actions
71 lines (62 loc) · 3.33 KB
/
Copy pathcommand-requirement_values.go
File metadata and controls
71 lines (62 loc) · 3.33 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cli
import "github.com/echocat/cli4g/codec"
// WithValueFlag adds a Set/String value flag, keeping T as the field/value type.
func (this *CommandRequirement[O]) WithValueFlag[T any, TP interface {
*T
codec.Value
}](name string, configure ...func(*FlagRequirement[T, []string])) *CommandRequirement[O] {
return this.WithFlag(newConfiguredFlagFactory(func() (codec.Codec[T, []string], error) {
return codec.NewValue[T, TP]()
}, name, configure...))
}
// WithValuePFlag adds a Set/String flag with a fresh pointer factory.
func (this *CommandRequirement[O]) WithValuePFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[T, []string])) *CommandRequirement[O] {
return this.WithFlag(newConfiguredFlagFactory(func() (codec.Codec[T, []string], error) {
return codec.NewValueP(factory)
}, name, configure...))
}
// WithValueSliceFlag adds a standard repeated slice flag of Set/String values.
func (this *CommandRequirement[O]) WithValueSliceFlag[T any, TP interface {
*T
codec.Value
}](name string, configure ...func(*FlagRequirement[[]T, [][]string])) *CommandRequirement[O] {
return this.WithFlag(newConfiguredFlagFactory(func() (codec.Codec[[]T, [][]string], error) {
return codec.NewValueSlice[T, TP]()
}, name, configure...))
}
// WithValuePSliceFlag adds a repeated slice flag of factory-created pointers.
func (this *CommandRequirement[O]) WithValuePSliceFlag[T codec.Value](name string, factory func() T, configure ...func(*FlagRequirement[[]T, [][]string])) *CommandRequirement[O] {
return this.WithFlag(newConfiguredFlagFactory(func() (codec.Codec[[]T, [][]string], error) {
return codec.NewValuePSlice(factory)
}, name, configure...))
}
// WithValueArgument adds a positional Set/String value argument.
func (this *CommandRequirement[O]) WithValueArgument[T any, TP interface {
*T
codec.Value
}](name string, configure ...func(*ArgumentRequirement[T, []string])) *CommandRequirement[O] {
return this.WithArgument(newConfiguredArgumentFactory(func() (codec.Codec[T, []string], error) {
return codec.NewValue[T, TP]()
}, name, configure...))
}
// WithValuePArgument adds a positional value with a fresh pointer factory.
func (this *CommandRequirement[O]) WithValuePArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[T, []string])) *CommandRequirement[O] {
return this.WithArgument(newConfiguredArgumentFactory(func() (codec.Codec[T, []string], error) {
return codec.NewValueP(factory)
}, name, configure...))
}
// WithValueSliceArgument adds a final variadic slice of Set/String values.
func (this *CommandRequirement[O]) WithValueSliceArgument[T any, TP interface {
*T
codec.Value
}](name string, configure ...func(*ArgumentRequirement[[]T, [][]string])) *CommandRequirement[O] {
return this.WithArgument(newConfiguredArgumentFactory(func() (codec.Codec[[]T, [][]string], error) {
return codec.NewValueSlice[T, TP]()
}, name, configure...))
}
// WithValuePSliceArgument adds a final variadic slice of factory-created pointers.
func (this *CommandRequirement[O]) WithValuePSliceArgument[T codec.Value](name string, factory func() T, configure ...func(*ArgumentRequirement[[]T, [][]string])) *CommandRequirement[O] {
return this.WithArgument(newConfiguredArgumentFactory(func() (codec.Codec[[]T, [][]string], error) {
return codec.NewValuePSlice(factory)
}, name, configure...))
}