/
defaults.go
72 lines (57 loc) · 1.6 KB
/
defaults.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cmd
import (
"fmt"
"github.com/cagedtornado/centralconfig/datastores"
"github.com/spf13/cobra"
)
var (
jsonConfig bool
yamlConfig bool
mysqlDDL bool
mssqlDDL bool
)
var yamlDefault = []byte(`
server:
port: 3000
datastore:
type: boltdb
database: config.db
`)
var jsonDefault = []byte(`{
"server" : {
"port": "3000"
},
"datastore" : {
"type": "boltdb",
"database": "config.db"
}
}`)
// defaultsCmd represents the defaults command
var defaultsCmd = &cobra.Command{
Use: "defaults",
Short: "Prints default server configuration files or DDL",
Long: `Use this to create a default configuration file for the centralconfig server.
Example:
centralconfig defaults > centralconfig.yaml
You can also use this to print SQL database scripts to create your datastore. Example:
centralconfig defaults --mysql > centralconfigdb.sql
`,
Run: func(cmd *cobra.Command, args []string) {
if jsonConfig {
fmt.Printf("%s", jsonDefault)
} else if mysqlDDL {
fmt.Printf("%s", datastores.GetMysqlCreateDDL())
} else if mssqlDDL {
fmt.Printf("%s", datastores.GetMSsqlCreateDDL())
} else if yamlConfig {
fmt.Printf("%s", yamlDefault)
}
},
}
func init() {
RootCmd.AddCommand(defaultsCmd)
defaultsCmd.Flags().BoolVarP(&jsonConfig, "json", "j", false, "Create a JSON configuration file")
defaultsCmd.Flags().BoolVarP(&yamlConfig, "yaml", "y", true, "Create a YAML configuration file")
defaultsCmd.Flags().BoolVarP(&mysqlDDL, "mysql", "m", false, "Create a MySQL database script")
defaultsCmd.Flags().BoolVarP(&mssqlDDL, "mssql", "s", false, "Create a MSSQL database script")
}