Skip to content
This repository has been archived by the owner on Aug 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #14 from izzatzr/master
Browse files Browse the repository at this point in the history
fix "The system cannot find the path specified." for non UNIX system
  • Loading branch information
ricoberger authored Jan 5, 2021
2 parents ed0bbef + 580e1de commit 6b297ba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
18 changes: 9 additions & 9 deletions cmd/dash/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"

"github.com/ricoberger/dash/pkg/dashboard"
"github.com/ricoberger/dash/pkg/datasource"
Expand All @@ -27,10 +28,6 @@ var rootCmd = &cobra.Command{
Short: "dash - terminal dashboard.",
Long: "dash - terminal dashboard.",
Run: func(cmd *cobra.Command, args []string) {
if configDir == "~/.dash" {
configDir = os.Getenv("HOME") + "/.dash"
}

err := fLog.Init(configDir, debug)
if err != nil {
log.Fatalf("Could not open log file: %v", err)
Expand Down Expand Up @@ -59,10 +56,6 @@ var exploreCmd = &cobra.Command{
Short: "Explore the data in your datasource.",
Long: "Explore the data in your datasource.",
Run: func(cmd *cobra.Command, args []string) {
if configDir == "~/.dash" {
configDir = os.Getenv("HOME") + "/.dash"
}

err := fLog.Init(configDir, debug)
if err != nil {
log.Fatalf("Could not open log file: %v", err)
Expand Down Expand Up @@ -102,7 +95,14 @@ var versionCmd = &cobra.Command{
}

func init() {
rootCmd.PersistentFlags().StringVar(&configDir, "config.dir", "~/.dash", "Location of the datasources and dashboards folder.")
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatalf("Failed to get OS home directory: %v", err)
}

dashPath := filepath.Join(homeDir, ".dash")

rootCmd.PersistentFlags().StringVar(&configDir, "config.dir", dashPath, "Location of the datasources and dashboards folder.")
rootCmd.PersistentFlags().StringVar(&configInterval, "config.interval", "1h", "Interval to retrieve data for.")
rootCmd.PersistentFlags().StringVar(&configRefresh, "config.refresh", "5m", "Time between refreshs of the dashboard.")
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "Log debug information.")
Expand Down
9 changes: 7 additions & 2 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dashboard

import (
"io/ioutil"
"path/filepath"

"gopkg.in/yaml.v2"
)
Expand All @@ -19,7 +20,9 @@ type Dashboard struct {
}

func New(dir string) ([]Dashboard, error) {
files, err := ioutil.ReadDir(dir + "/dashboards")
dashboardDir := filepath.Join(dir, "dashboards")

files, err := ioutil.ReadDir(dashboardDir)
if err != nil {
return nil, err
}
Expand All @@ -29,7 +32,9 @@ func New(dir string) ([]Dashboard, error) {
for _, file := range files {
var dashboard Dashboard

data, err := ioutil.ReadFile(dir + "/dashboards/" + file.Name())
dashboardFile := filepath.Join(dashboardDir, file.Name())

data, err := ioutil.ReadFile(dashboardFile)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"io/ioutil"
"path/filepath"
"text/template"
"time"

Expand Down Expand Up @@ -55,7 +56,9 @@ type Client interface {
}

func New(dir string) (map[string]Client, error) {
files, err := ioutil.ReadDir(dir + "/datasources")
datasourceDir := filepath.Join(dir, "datasources")

files, err := ioutil.ReadDir(datasourceDir)
if err != nil {
return nil, err
}
Expand All @@ -65,8 +68,9 @@ func New(dir string) (map[string]Client, error) {

for _, file := range files {
var datasource Datasource
datasourceFile := filepath.Join(datasourceDir, file.Name())

data, err := ioutil.ReadFile(dir + "/datasources/" + file.Name())
data, err := ioutil.ReadFile(datasourceFile)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package log
import (
"log"
"os"
"path/filepath"
)

var (
Expand All @@ -15,7 +16,9 @@ func Init(dir string, debugEnabled bool) error {

var err error

f, err = os.OpenFile(dir+"/dash.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
dashLog := filepath.Join(dir, "dash.log")

f, err = os.OpenFile(dashLog, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return err
}
Expand Down

0 comments on commit 6b297ba

Please sign in to comment.