Ejemplo n.º 1
0
Archivo: ui.go Proyecto: vsco/dcdr
func (u *UI) DrawConfig(cfg *config.Config) {
	tbl := table.New("Component", "Name", "Value", "Description").WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)

	tbl.AddRow("Config", "ConfigPath", config.Path(), "Path to config.hcl")
	tbl.AddRow("Defaults", "Username", cfg.Username, "The username for commits. default: `whoami`")
	tbl.AddRow("Defaults", "Namespace", cfg.Namespace, "K/V namespace")

	tbl.AddRow("Watcher", "OutputPath", cfg.Watcher.OutputPath, "File path to watch and read from")

	tbl.AddRow("Server", "Endpoint", cfg.Server.Endpoint, "The path to serve (GET '/dcdr.json')")
	tbl.AddRow("Server", "Host", cfg.Server.Host, "The server host (:8000")
	tbl.AddRow("Server", "JSONRoot", cfg.Server.JSONRoot, "JSON root node ('dcdr')")

	if cfg.GitEnabled() {
		tbl.AddRow("Git", "RepoPath", cfg.Git.RepoPath, "Audit repo location")
		tbl.AddRow("Git", "RepoURL", cfg.Git.RepoURL, "Audit repo remote origin")
	}

	if cfg.StatsEnabled() {
		tbl.AddRow("Stats", "Namespace", cfg.Stats.Namespace, "Prefix for `dcdr` change events.")
		tbl.AddRow("Stats", "Host", cfg.Stats.Host, "Statsd host ('localhost')")
		tbl.AddRow("Stats", "Port", fmt.Sprintf("%d", cfg.Stats.Port), "Statsd port (8125)")
	}

	tbl.Print()
}
Ejemplo n.º 2
0
func (cc *Controller) Init(ctx climax.Context) int {
	if _, err := os.Stat(config.Path()); os.IsNotExist(err) {
		err = os.MkdirAll(path.Dir(config.Path()), filePerms)

		printer.Say("creating %s", path.Dir(config.Path()))

		if err != nil {
			printer.SayErr("could not create config directory: %v", err)
			return 1
		}

		err = ioutil.WriteFile(config.Path(), config.ExampleConfig, filePerms)
		printer.Say("%s not found. creating example config", config.Path())

		if err != nil {
			printer.SayErr("could not write config.hcl %v", err)
			return 1
		}
	}

	if !cc.Config.GitEnabled() {
		printer.Say("no repository configured. skipping")
		return 0
	}

	create := ctx.Is("create")

	err := cc.Client.InitRepo(create)

	if err != nil {
		printer.SayErr("%v", err)
		return 1
	}

	if create {
		printer.Say("initialized new repo in %s and pushed to %s",
			cc.Config.Git.RepoPath, cc.Config.Git.RepoURL)
	} else {
		printer.Say("cloned %s into %s",
			cc.Config.Git.RepoURL, cc.Config.Git.RepoPath)
	}

	return 0
}