-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.go
51 lines (42 loc) · 1.36 KB
/
string.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
45
46
47
48
49
50
51
package optparse
// StringValue represents a string value
type StringValue string
// StringValueAssertion defines an assertion if the Value is a StringValue
type StringValueAssertion interface {
Value
IsString() bool
}
// NewStringValue creates a new StringValue
func NewStringValue(val string, p *string) *StringValue {
*p = val
return (*StringValue)(p)
}
// Set sets the value
func (s *StringValue) Set(val string) error {
*s = StringValue(val)
return nil
}
// IsString returns true if the Value is a StringValue
func (s *StringValue) IsString() bool {
return true
}
// StringVar defines a string option with a pointer to its value
func (o *OptionParser) StringVar(p *string, long string, short rune, def string) {
opt := &Option{long, short, NewStringValue(def, p)}
o.Options = append(o.Options, opt)
}
// StringVar defines a string option with a pointer to its value
func StringVar(p *string, long string, short rune, def string) {
CommandLine.StringVar(p, long, short, def)
}
// String defines a string option and returns a pointer to its value
func (o *OptionParser) String(long string, short rune, def string) (p *string) {
p = new(string)
o.StringVar(p, long, short, def)
return
}
// String defines a string option and returns a pointer to its value
func String(long string, short rune, def string) (p *string) {
p = CommandLine.String(long, short, def)
return
}