mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 21:51:38 +00:00
Merge pull request #217 from neilalexander/json
Add -json flag for -genconf and -normaliseconf
This commit is contained in:
commit
8ade7aed62
24
yggdrasil.go
24
yggdrasil.go
@ -76,9 +76,15 @@ func generateConfig(isAutoconf bool) *nodeConfig {
|
|||||||
|
|
||||||
// Generates a new configuration and returns it in HJSON format. This is used
|
// Generates a new configuration and returns it in HJSON format. This is used
|
||||||
// with -genconf.
|
// with -genconf.
|
||||||
func doGenconf() string {
|
func doGenconf(isjson bool) string {
|
||||||
cfg := generateConfig(false)
|
cfg := generateConfig(false)
|
||||||
bs, err := hjson.Marshal(cfg)
|
var bs []byte
|
||||||
|
var err error
|
||||||
|
if isjson {
|
||||||
|
bs, err = json.MarshalIndent(cfg, "", " ")
|
||||||
|
} else {
|
||||||
|
bs, err = hjson.Marshal(cfg)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -89,9 +95,10 @@ func doGenconf() string {
|
|||||||
func main() {
|
func main() {
|
||||||
// Configure the command line parameters.
|
// Configure the command line parameters.
|
||||||
genconf := flag.Bool("genconf", false, "print a new config to stdout")
|
genconf := flag.Bool("genconf", false, "print a new config to stdout")
|
||||||
useconf := flag.Bool("useconf", false, "read config from stdin")
|
useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
|
||||||
useconffile := flag.String("useconffile", "", "read config from specified file path")
|
useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")
|
||||||
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
|
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
|
||||||
|
confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON")
|
||||||
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
|
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -186,7 +193,12 @@ func main() {
|
|||||||
// their configuration file with newly mapped names (like above) or to
|
// their configuration file with newly mapped names (like above) or to
|
||||||
// convert from plain JSON to commented HJSON.
|
// convert from plain JSON to commented HJSON.
|
||||||
if *normaliseconf {
|
if *normaliseconf {
|
||||||
bs, err := hjson.Marshal(cfg)
|
var bs []byte
|
||||||
|
if *confjson {
|
||||||
|
bs, err = json.MarshalIndent(cfg, "", " ")
|
||||||
|
} else {
|
||||||
|
bs, err = hjson.Marshal(cfg)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -195,7 +207,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
case *genconf:
|
case *genconf:
|
||||||
// Generate a new configuration and print it to stdout.
|
// Generate a new configuration and print it to stdout.
|
||||||
fmt.Println(doGenconf())
|
fmt.Println(doGenconf(*confjson))
|
||||||
default:
|
default:
|
||||||
// No flags were provided, therefore print the list of flags to stdout.
|
// No flags were provided, therefore print the list of flags to stdout.
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
Loading…
Reference in New Issue
Block a user