-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.go
More file actions
75 lines (61 loc) · 1.49 KB
/
config.go
File metadata and controls
75 lines (61 loc) · 1.49 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
package main
import (
"log"
"os"
"path/filepath"
"strings"
"github.com/spf13/viper"
cli "github.com/urfave/cli/v2"
)
func getFlags() []cli.Flag {
return []cli.Flag {
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "relative path to folder where is your code which needs to be scanned and injected with isecode numbers",
Destination: &path,
DefaultText: "current directory",
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "path to the config file",
Destination: &config,
DefaultText: "isecode.json",
},
}
}
func handlePath() {
if path == "" {
wd, err := os.Getwd()
if err != nil {
log.Println(err)
}
path = wd
log.Println("path set to current working directory: " + path)
}
}
func loadConfig() {
var dir, file string
if config != "" {
dir, file = filepath.Split(config)
file = strings.TrimSuffix(file, filepath.Ext(file))
} else {
file = "isecode"
}
if dir == "" {
dir = "."
}
viper.SetConfigName(file) // name of config file (without extension)
viper.SetConfigType("json") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath(dir) // optionally look for config in the working directory
err := viper.ReadInConfig() // Find and read the config file
if err != nil {
log.Println(err)
}
matchFiles = viper.GetString("MATCH_FILES")
matchString = viper.GetString("MATCH_STRING")
}
func getPrefix() {
prefix = viper.GetString("CODE_PREFIX")
}