grafana-backuper/internal/config/config.go

37 lines
1.1 KiB
Go
Raw Normal View History

2024-07-01 00:54:05 +02:00
package config
import (
"flag"
"os"
"github.com/peterbourgon/ff"
)
const envVarPrefix = "GB"
type Config struct {
ForceCommits bool
GrafanaURL string
GrafanaToken string
GitBranch string
GitRepo string
GitUser string
GitEmail string
GitPass string
GPGKey string
}
func (c *Config) RegisterFlags(fs *flag.FlagSet) error {
fs.BoolVar(&c.ForceCommits, "force-commits", false, "Force git commits / ignore existence check")
fs.StringVar(&c.GrafanaURL, "grafana-url", "", "Grafana URL to access the API")
fs.StringVar(&c.GrafanaToken, "grafana-token", "", "Grafana auth token to access the API")
fs.StringVar(&c.GitBranch, "git-branch", "main", "Git branch name")
fs.StringVar(&c.GitRepo, "git-repo", "", "Complete Git repository URL")
fs.StringVar(&c.GitUser, "git-user", "", "Git username")
fs.StringVar(&c.GitEmail, "git-email", "", "Git email address")
fs.StringVar(&c.GitPass, "git-pass", "", "Git user password")
fs.StringVar(&c.GPGKey, "signing-key", "", "Path to the GPG signing key")
return ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix(envVarPrefix))
}