Add more CLI commands

This commit is contained in:
Gabriel Adrian Samfira 2022-05-03 12:40:59 +00:00
parent 475d424f32
commit 8ceafff09b
21 changed files with 995 additions and 107 deletions

View file

@ -35,6 +35,14 @@ func LoadConfig() (*Config, error) {
return nil, errors.Wrap(err, "fetching config")
}
if _, err := os.Stat(cfgFile); err != nil {
if errors.Is(err, os.ErrNotExist) {
// return empty config
return &Config{}, nil
}
return nil, errors.Wrap(err, "accessing config file")
}
var config Config
if _, err := toml.DecodeFile(cfgFile, &config); err != nil {
return nil, errors.Wrap(err, "decoding toml")

View file

@ -4,16 +4,17 @@
package config
import (
"fmt"
"os"
"path/filepath"
"github.com/pkg/errors"
)
func getHomeDir() (string, error) {
home := os.Getenv("HOME")
home, err := os.UserHomeDir()
if home == "" {
return "", fmt.Errorf("failed to get home folder")
if err != nil {
return "", errors.Wrap(err, "fetching home dir")
}
return filepath.Join(home, ".local", "share", DefaultAppFolder), nil