-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1337334
commit 491a24a
Showing
2 changed files
with
145 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"gopkg.in/urfave/cli.v1" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type configFile struct { | ||
APIKey string `yaml:"apiKey"` | ||
APIHost string `yaml:"apiHost"` | ||
Debug bool `yaml:"debug"` | ||
Identities string `yaml:"identities"` | ||
Labels string `yaml:"labels"` | ||
Environment string `yaml:"environment"` | ||
Service string `yaml:"service"` | ||
} | ||
|
||
func initCmd(c *cli.Context) error { | ||
|
||
out := c.GlobalString("config") | ||
if out == "" { | ||
out = "/tmp/firehydrant.cfg" | ||
} | ||
|
||
config := configFile{} | ||
if len(c.GlobalString("apiKey")) > 0 { | ||
config.APIKey = c.GlobalString("apiKey") | ||
} | ||
|
||
if len(c.GlobalString("apiHost")) > 0 { | ||
config.APIHost = c.GlobalString("apiHost") | ||
} | ||
|
||
config.Debug = c.GlobalBool("debug") | ||
|
||
if len(c.String("identities")) > 0 { | ||
config.Identities = c.String("identities") | ||
} | ||
|
||
if len(c.String("labels")) > 0 { | ||
config.Labels = c.String("labels") | ||
} | ||
|
||
if len(c.String("environment")) > 0 { | ||
config.Environment = c.String("environment") | ||
} | ||
|
||
if len(c.String("service")) > 0 { | ||
config.Service = c.String("service") | ||
} | ||
|
||
d, err := yaml.Marshal(config) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
err = ioutil.WriteFile(out, d, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(fmt.Sprintf("Wrote config file %s", out)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters