-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_reader.go
More file actions
80 lines (70 loc) · 1.57 KB
/
config_reader.go
File metadata and controls
80 lines (70 loc) · 1.57 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"os"
"github.com/gen1us2k/log"
"github.com/urfave/cli"
)
var (
Version string
LogLevel string
FilePath string
)
type Configuration struct {
customConfig *CustomConfig
app *cli.App
}
func NewConfigurator() *Configuration {
Version = "0.0.0"
app := cli.NewApp()
app.Name = "apidoctool"
app.Usage = "generate markdown docs with swagger spec"
return &Configuration{
customConfig: &CustomConfig{},
app: app,
}
}
func (c *Configuration) fillConfig() *CustomConfig {
return &CustomConfig{
FilePath: FilePath,
}
}
func (c *Configuration) After(cb func(c *cli.Context) error) {
c.app.After = func(ctx *cli.Context) error {
log.SetLevel(log.MustParseLevel(LogLevel))
c.customConfig = c.fillConfig()
return cb(ctx)
}
}
func (c *Configuration) Run() error {
c.app.Before = func(ctx *cli.Context) error {
log.SetLevel(log.MustParseLevel(LogLevel))
return nil
}
c.app.Flags = c.setupFlags()
return c.app.Run(os.Args)
}
func (c *Configuration) App() *cli.App {
return c.app
}
func (c *Configuration) setupFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "loglevel, l",
Value: "debug",
Usage: "set log level",
Destination: &LogLevel,
EnvVar: "LOG_LEVEL",
},
cli.StringFlag{
Name: "FilePath, f",
Value: "swagger.json",
Usage: "swagger spec file or swagger spec url",
EnvVar: "SWAGGER_SPEC_FILEPATH",
Destination: &FilePath,
},
}
}
func (c *Configuration) Get() *CustomConfig {
c.customConfig = c.fillConfig()
return c.customConfig
}