Skip to content

Commit

Permalink
Check if configuration file exists and is not a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
bensallen committed Aug 4, 2019
1 parent 39d8bb5 commit 5749048
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package root

import (
"fmt"
"os"

"github.com/BurntSushi/toml"
"github.com/bensallen/hkmgr/internal/config"
Expand Down Expand Up @@ -76,6 +77,15 @@ func Run() error {
debug = true
}

cfgStat, err := os.Stat(configPath)

if os.IsNotExist(err) {
return fmt.Errorf("configuration file %s not found", configPath)
}
if cfgStat.IsDir() {
return fmt.Errorf("configuration file %s is a directory", configPath)
}

var config config.Config
if _, err := toml.DecodeFile(configPath, &config); err != nil {
return err
Expand Down

0 comments on commit 5749048

Please sign in to comment.