add grafana package & temporary debug checks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1247fc3fcb
commit
2d08f75545
9 changed files with 373 additions and 0 deletions
55
cfg/cfg.go
Normal file
55
cfg/cfg.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package cfg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
)
|
||||
|
||||
type AppSettings struct {
|
||||
GrafanaURL string
|
||||
Token string
|
||||
}
|
||||
|
||||
var cliStruct struct {
|
||||
GrafanaURL string `name:"grafana-url" env:"GRAFANA_URL" help:"Grafana URL to access the API"`
|
||||
AuthToken string `name:"grafana-auth-token" env:"GRAFANA_AUTH_TOKEN" help:"Grafana auth token to access the API"`
|
||||
}
|
||||
|
||||
func Parse() *AppSettings {
|
||||
ctx := kong.Parse(
|
||||
&cliStruct,
|
||||
kong.Name("grafana-backuper"),
|
||||
kong.Description("🚀 CLI tool to backup grafana dashboards"),
|
||||
kong.UsageOnError(),
|
||||
)
|
||||
|
||||
validateFlags(ctx)
|
||||
settings := &AppSettings{
|
||||
GrafanaURL: cliStruct.GrafanaURL,
|
||||
Token: cliStruct.AuthToken,
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
func validateFlags(cliCtx *kong.Context) {
|
||||
var flagsValid = true
|
||||
var messages = []string{}
|
||||
if cliStruct.GrafanaURL == "" {
|
||||
messages = append(messages, "error: invalid grafana URL, must not be blank")
|
||||
flagsValid = false
|
||||
}
|
||||
if cliStruct.AuthToken == "" {
|
||||
messages = append(messages, "error: invalid auth token for grafana, must not be blank")
|
||||
flagsValid = false
|
||||
}
|
||||
if !flagsValid {
|
||||
cliCtx.PrintUsage(false)
|
||||
fmt.Println()
|
||||
for i := 0; i < len(messages); i++ {
|
||||
fmt.Println(messages[i])
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue