Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 6319999

Browse files
committed
Fix bug releated to config file handling
1 parent 46054bb commit 6319999

File tree

6 files changed

+71
-19
lines changed

6 files changed

+71
-19
lines changed

cmd/config.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ func dashPath() string {
174174
// Map config and return it with the config path
175175
func mapConfig(cfgFile string) (config, string) {
176176
if cfgFile == "" {
177-
cfgFile = createConfig(dashPath(), "default.yml", defaultConfig())
177+
cfgFile = "default.yml"
178+
createConfig(dashPath(), cfgFile, defaultConfig())
178179
}
179180

180181
// viper.AddConfigPath(home)
181-
viper.AddConfigPath(".")
182182
viper.AddConfigPath(dashPath())
183+
viper.AddConfigPath(".")
183184

184185
viper.SetConfigName(removeExt(cfgFile))
185186
err := viper.ReadInConfig()
@@ -211,7 +212,7 @@ func mapConfig(cfgFile string) (config, string) {
211212
}
212213

213214
func removeExt(filepath string) string {
214-
ext := []string{".json", ".yml", ".yaml"}
215+
ext := []string{".json", ".yml", ".yaml", ".toml"}
215216
for _, v := range ext {
216217
filepath = strings.Replace(filepath, v, "", -1)
217218
}
@@ -247,7 +248,7 @@ func tryReadFile(cfgFile string) {
247248

248249
f, err := ioutil.ReadFile(cfgFile)
249250
if err != nil {
250-
panic(fmt.Errorf("could not read file %s data", cfgFile))
251+
panic(fmt.Errorf("could not read file %s", cfgFile))
251252
}
252253

253254
viper.SetConfigType(strings.Trim(filepath.Ext(cfgFile), "."))

cmd/edit.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"os"
66
"os/exec"
77
"path/filepath"
8-
"strings"
98

109
"github.com/spf13/cobra"
1110
)
@@ -50,11 +49,7 @@ func editDashboard(editor string, config string) {
5049
func findConfigFile(search string) string {
5150
fs := getConfigFiles()
5251
for _, v := range fs {
53-
s := strings.Split(v.Name(), ".")
54-
if search == s[0] || search == v.Name() {
55-
fmt.Println(s[0])
56-
fmt.Println(v.Name())
57-
fmt.Println(search)
52+
if search == removeExt(v.Name()) || search == v.Name() {
5853
return v.Name()
5954
}
6055
}

cmd/root.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
var (
1717
// Used for flags
18-
file string
18+
cfgName string
1919
logpath string
2020
debug bool
2121

@@ -30,7 +30,7 @@ var (
3030
)
3131

3232
func init() {
33-
rootCmd.Flags().StringVarP(&file, "config", "c", "", "A valid dashboard configuration")
33+
rootCmd.Flags().StringVarP(&cfgName, "config", "c", "", "A valid dashboard configuration")
3434
// TODO logger
3535
// rootCmd.Flags().StringVarP(&logpath, "logpath", "l", "", "Path for logging")
3636
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Debug Mode - doesn't display graph")
@@ -59,7 +59,10 @@ func run() {
5959
defer tui.Close()
6060

6161
// Map dashboard config to a struct Config.
62-
cfg, file := mapConfig(file)
62+
cfg, cfgFile := mapConfig(cfgName)
63+
if debug {
64+
fmt.Fprintf(os.Stdout, "Config file used: %s", cfgFile)
65+
}
6366

6467
// Passing a time.Time to this channel reload the entire dashboard.
6568
hotReload := make(chan time.Time)
@@ -83,20 +86,20 @@ func run() {
8386
cfg.KEdit(),
8487
func() {
8588
stopReload(stopAutoReload)
86-
editDashboard(editor, file)
89+
editDashboard(editor, cfgFile)
8790
hotReload <- time.Now()
8891
autoReload(cfg.RefreshTime(), stopAutoReload, hotReload)
8992
},
9093
)
9194

9295
// First display.
93-
build(file, tui)
96+
build(cfgName, tui)
9497

9598
// Automatic reload
9699
go func() {
97100
for hr := range hotReload {
98101
tui.HotReload()
99-
build(file, tui)
102+
build(cfgName, tui)
100103
if debug {
101104
fmt.Println("Last reload: " + hr.Format("2006-01-02 15:04:05"))
102105
}

example/ga-1.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ projects:
1313
bold: true
1414
services:
1515
google_analytics:
16-
keyfile: goanalytics-123.json
1716
view_id: 12345678
1817
monitor:
1918
address: "https://www.web-techno.net"

example/monitor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ projects:
88
- name: Default Configuration - You can modify at at $XDG_CONFIG_HOME/devdash/devdash.yml
99
services:
1010
monitor:
11-
address: "https://thevaluable.dev"
11+
address: "https://thevaluable.dev/sdifljasflkafjsdfljfksasdflk"
1212
widgets:
1313
- row:
1414
- col:
15-
size: "M"
15+
size: "12"
1616
elements:
1717
- name: mon.box_availability
1818
options:

internal/templates.go

+54
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,57 @@ projects:
258258
start_date: 35_weeks_ago
259259
`
260260
}
261+
262+
func localhost() string {
263+
return `---
264+
projects:
265+
- name: General
266+
services:
267+
github:
268+
{{ .Token }}
269+
{{ .Owner }}
270+
widgets:
271+
- row:
272+
- col:
273+
size: "4"
274+
elements:
275+
- name: github.table_repositories
276+
options:
277+
color: yellow
278+
row_limit: 30
279+
- col:
280+
size: "5"
281+
elements:
282+
- name: lh.box
283+
options:
284+
title: " Cow says "
285+
command: "fortune wisdom | cowsay"
286+
height: 20
287+
- name: lh.table_disk
288+
options:
289+
title: " Disks "
290+
row_limit: 3
291+
color: blue
292+
- name: github.table_issues
293+
options:
294+
color: red
295+
row_limit: 10
296+
repository: devdash
297+
- col:
298+
size: 3
299+
elements:
300+
- name: lh.box
301+
options:
302+
title: " Weather - Berlin "
303+
color: yellow
304+
height: 8
305+
command: "curl --stderr - --silent wttr.in/berlin?T0Q"
306+
- name: lh.table
307+
options:
308+
title: " Dashboards "
309+
title_color: cyan
310+
border_color: blue
311+
text_color: green
312+
command: "ls | grep yml"
313+
`
314+
}

0 commit comments

Comments
 (0)