/
options.go
55 lines (48 loc) · 1.29 KB
/
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
package codegen
import (
"flag"
"strings"
"github.com/go-errors/errors"
"github.com/viant/toolbox"
"github.com/viant/toolbox/url"
)
type Options struct {
Source string
Dest string
Types []string
PoolObjects bool
TagName string
Pkg string
}
func (o *Options) Validate() error {
if o.Source == "" {
return errors.New("Source was empty")
}
if len(o.Types) == 0 {
return errors.New("Types was empty")
}
return nil
}
const (
optionKeySource = "s"
optionKeyDest = "o"
optionKeyTypes = "t"
optionKeyTagName = "a"
optionKeyPoolObjects = "p"
optionKeyPkg = "pkg"
)
//NewOptionsWithFlagSet creates a new options for the supplide flagset
func NewOptionsWithFlagSet(set *flag.FlagSet) *Options {
toolbox.Dump(set)
var result = &Options{}
result.Dest = set.Lookup(optionKeyDest).Value.String()
result.Source = set.Lookup(optionKeySource).Value.String()
result.PoolObjects = toolbox.AsBoolean(set.Lookup(optionKeyPoolObjects).Value.String())
result.TagName = set.Lookup(optionKeyTagName).Value.String()
result.Types = strings.Split(set.Lookup(optionKeyTypes).Value.String(), ",")
result.Pkg = set.Lookup(optionKeyPkg).Value.String()
if result.Source == "" {
result.Source = url.NewResource(".").ParsedURL.Path
}
return result
}