-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
56 lines (48 loc) · 975 Bytes
/
options.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
package options
import (
"strconv"
"github.com/spf13/viper"
)
var Version string = "v1.0.0"
var Letters string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var Numbers string = "0123456789"
var Symbols string = "~!@#$%^&*()"
var Length int = 8
type Options struct {
All bool
Letter bool
Number bool
Symbol bool
Length int
}
func NewOptions(args []string) (opts *Options) {
opts = &Options{
All: viper.GetBool("all"),
Letter: viper.GetBool("letter"),
Number: viper.GetBool("number"),
Symbol: viper.GetBool("symbol"),
Length: viper.GetInt("length"),
}
if opts.All {
opts.Letter = true
opts.Number = true
opts.Symbol = true
}
if !opts.Letter && !opts.Number && !opts.Symbol {
opts.Letter = true
opts.Number = true
}
if len(args) == 1 {
l, err := strconv.Atoi(args[0])
if err != nil {
l = Length
}
opts.Length = l
} else {
opts.Length = Length
}
if opts.Length < 1 {
opts.Length = Length
}
return
}