/
gflag.go
65 lines (53 loc) · 1.66 KB
/
gflag.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
56
57
58
59
60
61
62
63
64
65
// Package gflag provide command line options and arguments binding, parse, management.
package gflag
import (
"github.com/gookit/goutil/cflag"
"github.com/gookit/goutil/strutil"
)
const (
// AlignLeft Align right, padding left
AlignLeft = strutil.PosRight
// AlignRight Align left, padding right
AlignRight = strutil.PosLeft
// default desc
defaultDesc = "No description"
// TagRuleNamed struct tag use named k-v rule.
//
// eg: `flag:"name=int0;shorts=i;required=true;desc=int option message"`
TagRuleNamed = 0
// TagRuleSimple struct tag use simple rule.
// format: "desc;required;default;shorts"
//
// eg: `flag:"int option message;required;;i"`
TagRuleSimple = 1
)
// FlagTagName default tag name on struct
var FlagTagName = "flag"
// Config for render help information
type Config struct {
// WithoutType don't display flag data type on print help
WithoutType bool
// DescNewline flag desc at new line on print help
DescNewline bool
// Alignment flag name align left or right. default is: left
Alignment uint8
// TagName on struct
TagName string
// TagRuleType for struct tag value. default is TagRuleNamed
TagRuleType uint8
// DisableArg disable binding arguments.
DisableArg bool
}
// OptCategory struct
type OptCategory struct {
Name, Title string
OptNames []string
}
// Ints The int flag list, implemented flag.Value interface
type Ints = cflag.Ints
// Strings The string flag list, implemented flag.Value interface
type Strings = cflag.Strings
// Booleans The bool flag list, implemented flag.Value interface
type Booleans = cflag.Booleans
// EnumString The string flag list, implemented flag.Value interface
type EnumString = cflag.EnumString