-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpositional.go
55 lines (49 loc) · 1.13 KB
/
positional.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
52
53
54
55
package argumentative
import (
"fmt"
)
// struct for a single configured positional argument
type Positional struct {
Longflag string
Description string
Required bool
Default string
Value *string
}
// Factory to generate a new positional argument
func NewPositional(longflag string, required bool, defaultvalue string, description string) Positional {
positional := Positional{
Longflag: longflag,
Description: description,
Required: required,
Default: defaultvalue,
Value: new(string),
}
if defaultvalue != "" {
*positional.Value = defaultvalue
}
return positional
}
// Generate the string for the long description
func (f *Positional) GetLongDescription() string {
output := fmt.Sprintf("%-25s", f.Longflag)
if f.Description != "" {
output += f.Description
}
if f.Default != "" {
output += " (Default: " + f.Default + ")"
}
return output
}
// Generate the string for a short description in the 'Usage:' line
func (f *Positional) GetShortDescription() string {
output := " "
if !f.Required {
output += "["
}
output += f.Longflag
if !f.Required {
output += "]"
}
return output
}