summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthieu <matthieu.cneude@gmail.com>2021-04-24 14:39:13 +0200
committermatthieu <matthieu.cneude@gmail.com>2021-04-24 14:39:13 +0200
commit631999993c3a905ac255535d1de0efc97c92b014 (patch)
treed6117423212d4f9d1f66430b257325104902e232
parent46054bbdf90950eadf5bb1c798328c572c7b1fb0 (diff)
Fix bug releated to config file handlingnext-release
-rw-r--r--cmd/config.go9
-rw-r--r--cmd/edit.go7
-rw-r--r--cmd/root.go15
-rw-r--r--example/ga-1.yml1
-rw-r--r--example/monitor.yml4
-rw-r--r--internal/templates.go54
6 files changed, 71 insertions, 19 deletions
diff --git a/cmd/config.go b/cmd/config.go
index 56745ad..a0cbe90 100644
--- a/cmd/config.go
+++ b/cmd/config.go
@@ -174,12 +174,13 @@ func dashPath() string {
// Map config and return it with the config path
func mapConfig(cfgFile string) (config, string) {
if cfgFile == "" {
- cfgFile = createConfig(dashPath(), "default.yml", defaultConfig())
+ cfgFile = "default.yml"
+ createConfig(dashPath(), cfgFile, defaultConfig())
}
// viper.AddConfigPath(home)
- viper.AddConfigPath(".")
viper.AddConfigPath(dashPath())
+ viper.AddConfigPath(".")
viper.SetConfigName(removeExt(cfgFile))
err := viper.ReadInConfig()
@@ -211,7 +212,7 @@ func mapConfig(cfgFile string) (config, string) {
}
func removeExt(filepath string) string {
- ext := []string{".json", ".yml", ".yaml"}
+ ext := []string{".json", ".yml", ".yaml", ".toml"}
for _, v := range ext {
filepath = strings.Replace(filepath, v, "", -1)
}
@@ -247,7 +248,7 @@ func tryReadFile(cfgFile string) {
f, err := ioutil.ReadFile(cfgFile)
if err != nil {
- panic(fmt.Errorf("could not read file %s data", cfgFile))
+ panic(fmt.Errorf("could not read file %s", cfgFile))
}
viper.SetConfigType(strings.Trim(filepath.Ext(cfgFile), "."))
diff --git a/cmd/edit.go b/cmd/edit.go
index b28e6c2..8cc1360 100644
--- a/cmd/edit.go
+++ b/cmd/edit.go
@@ -5,7 +5,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "strings"
"github.com/spf13/cobra"
)
@@ -50,11 +49,7 @@ func editDashboard(editor string, config string) {
func findConfigFile(search string) string {
fs := getConfigFiles()
for _, v := range fs {
- s := strings.Split(v.Name(), ".")
- if search == s[0] || search == v.Name() {
- fmt.Println(s[0])
- fmt.Println(v.Name())
- fmt.Println(search)
+ if search == removeExt(v.Name()) || search == v.Name() {
return v.Name()
}
}
diff --git a/cmd/root.go b/cmd/root.go
index 8fa59eb..3cbefc4 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -15,7 +15,7 @@ import (
var (
// Used for flags
- file string
+ cfgName string
logpath string
debug bool
@@ -30,7 +30,7 @@ var (
)
func init() {
- rootCmd.Flags().StringVarP(&file, "config", "c", "", "A valid dashboard configuration")
+ rootCmd.Flags().StringVarP(&cfgName, "config", "c", "", "A valid dashboard configuration")
// TODO logger
// rootCmd.Flags().StringVarP(&logpath, "logpath", "l", "", "Path for logging")
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Debug Mode - doesn't display graph")
@@ -59,7 +59,10 @@ func run() {
defer tui.Close()
// Map dashboard config to a struct Config.
- cfg, file := mapConfig(file)
+ cfg, cfgFile := mapConfig(cfgName)
+ if debug {
+ fmt.Fprintf(os.Stdout, "Config file used: %s", cfgFile)
+ }
// Passing a time.Time to this channel reload the entire dashboard.
hotReload := make(chan time.Time)
@@ -83,20 +86,20 @@ func run() {
cfg.KEdit(),
func() {
stopReload(stopAutoReload)
- editDashboard(editor, file)
+ editDashboard(editor, cfgFile)
hotReload <- time.Now()
autoReload(cfg.RefreshTime(), stopAutoReload, hotReload)
},
)
// First display.
- build(file, tui)
+ build(cfgName, tui)
// Automatic reload
go func() {
for hr := range hotReload {
tui.HotReload()
- build(file, tui)
+ build(cfgName, tui)
if debug {
fmt.Println("Last reload: " + hr.Format("2006-01-02 15:04:05"))
}
diff --git a/example/ga-1.yml b/example/ga-1.yml
index 6021fe1..6b1c1a6 100644
--- a/example/ga-1.yml
+++ b/example/ga-1.yml
@@ -13,7 +13,6 @@ projects:
bold: true
services:
google_analytics:
- keyfile: goanalytics-123.json
view_id: 12345678
monitor:
address: "https://www.web-techno.net"
diff --git a/example/monitor.yml b/example/monitor.yml
index 525b4af..5b14435 100644
--- a/example/monitor.yml
+++ b/example/monitor.yml
@@ -8,11 +8,11 @@ projects:
- name: Default Configuration - You can modify at at $XDG_CONFIG_HOME/devdash/devdash.yml
services:
monitor:
- address: "https://thevaluable.dev"
+ address: "https://thevaluable.dev/sdifljasflkafjsdfljfksasdflk"
widgets:
- row:
- col:
- size: "M"
+ size: "12"
elements:
- name: mon.box_availability
options:
diff --git a/internal/templates.go b/internal/templates.go
index 29ea69d..95eedae 100644
--- a/internal/templates.go
+++ b/internal/templates.go
@@ -258,3 +258,57 @@ projects:
start_date: 35_weeks_ago
`
}
+
+func localhost() string {
+ return `---
+projects:
+ - name: General
+ services:
+ github:
+ {{ .Token }}
+ {{ .Owner }}
+ widgets:
+ - row:
+ - col:
+ size: "4"
+ elements:
+ - name: github.table_repositories
+ options:
+ color: yellow
+ row_limit: 30
+ - col:
+ size: "5"
+ elements:
+ - name: lh.box
+ options:
+ title: " Cow says "
+ command: "fortune wisdom | cowsay"
+ height: 20
+ - name: lh.table_disk
+ options:
+ title: " Disks "
+ row_limit: 3
+ color: blue
+ - name: github.table_issues
+ options:
+ color: red
+ row_limit: 10
+ repository: devdash
+ - col:
+ size: 3
+ elements:
+ - name: lh.box
+ options:
+ title: " Weather - Berlin "
+ color: yellow
+ height: 8
+ command: "curl --stderr - --silent wttr.in/berlin?T0Q"
+ - name: lh.table
+ options:
+ title: " Dashboards "
+ title_color: cyan
+ border_color: blue
+ text_color: green
+ command: "ls | grep yml"
+`
+}