-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathtest-config.go
52 lines (41 loc) · 1.14 KB
/
test-config.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
package commands
import (
"fmt"
"os"
"github.com/activecm/rita-legacy/config"
"github.com/activecm/rita-legacy/resources"
"github.com/urfave/cli"
yaml "gopkg.in/yaml.v2"
)
func init() {
command := cli.Command{
Flags: []cli.Flag{ConfigFlag},
Name: "test-config",
Usage: "Check the configuration file for validity",
Before: SetConfigFilePath,
Action: testConfiguration,
}
allCommands = append(allCommands, command)
}
// testConfiguration prints out the result of parsing the config file
func testConfiguration(c *cli.Context) error {
// First, print out the config as it was parsed
conf, err := config.LoadConfig(getConfigFilePath(c))
if err != nil {
fmt.Fprintf(os.Stdout, "Failed to config: %s\n", err.Error())
os.Exit(-1)
}
staticConfig, err := yaml.Marshal(conf.S)
if err != nil {
return err
}
tableConfig, err := yaml.Marshal(conf.T)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "\n%s\n", string(staticConfig))
fmt.Fprintf(os.Stdout, "\n%s\n", string(tableConfig))
// Then test initializing external resources like db connection and file handles
resources.InitResources(getConfigFilePath(c))
return nil
}