remove logger from cli, default config path

This commit is contained in:
Erik Winter 2021-07-09 07:45:09 +02:00
parent d82f4b7c0a
commit 141a20461f
1 changed files with 4 additions and 12 deletions

View File

@ -4,38 +4,30 @@ import (
"fmt" "fmt"
"os" "os"
"git.ewintr.nl/go-kit/log"
"git.ewintr.nl/gte/cmd/cli/command" "git.ewintr.nl/gte/cmd/cli/command"
"git.ewintr.nl/gte/internal/configuration" "git.ewintr.nl/gte/internal/configuration"
) )
func main() { func main() {
loglevel := log.LogLevel("error") configPath := "./gte.conf"
if os.Getenv("GTE_LOGLEVEL") != "" {
loglevel = log.LogLevel(os.Getenv("GTE_LOGLEVEL"))
}
logger := log.New(os.Stdout).WithField("cmd", "cli")
logger.SetLogLevel(loglevel)
configPath := "/home/erik/.config/gte/gte.conf"
if os.Getenv("GTE_CONFIG") != "" { if os.Getenv("GTE_CONFIG") != "" {
configPath = os.Getenv("GTE_CONFIG") configPath = os.Getenv("GTE_CONFIG")
} }
configFile, err := os.Open(configPath) configFile, err := os.Open(configPath)
if err != nil { if err != nil {
logger.WithErr(err).Error("could not open config file") fmt.Println(err, "could not open config file")
os.Exit(1) os.Exit(1)
} }
config := configuration.New(configFile) config := configuration.New(configFile)
cmd, err := command.Parse(os.Args[1:], config) cmd, err := command.Parse(os.Args[1:], config)
if err != nil { if err != nil {
logger.WithErr(err).Error("could not initialize command") fmt.Println(err, "could not initialize command")
os.Exit(1) os.Exit(1)
} }
result, err := cmd.Do() result, err := cmd.Do()
if err != nil { if err != nil {
logger.WithErr(err).Error("could perform command") fmt.Println(err, "could not perform command")
os.Exit(1) os.Exit(1)
} }
fmt.Printf("%s\n", result.Message) fmt.Printf("%s\n", result.Message)