Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Feb 16, 2024
1 parent 974e5ee commit 1c3c0a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
7 changes: 5 additions & 2 deletions cmd/root.go
Expand Up @@ -92,7 +92,10 @@ func init() {
"",
"use this configuration file (default is $GH_DASH_CONFIG, or if not set, \n$XDG_CONFIG_HOME/gh-dash/config.yml)",
)
rootCmd.MarkFlagFilename("config", "yaml", "yml")
err := rootCmd.MarkPersistentFlagFilename("config", "yaml", "yml")
if err != nil {
log.Fatal("Cannot mark config flag as filename", err)
}

rootCmd.Version = buildVersion(Version, Commit, Date, BuiltBy)
rootCmd.SetVersionTemplate(`gh-dash {{printf "version %s\n" .Version}}`)
Expand All @@ -110,7 +113,7 @@ func init() {
"help for gh-dash",
)

rootCmd.Run = func(cmd *cobra.Command, args []string) {
rootCmd.Run = func(_ *cobra.Command, _ []string) {
debug, err := rootCmd.Flags().GetBool("debug")
if err != nil {
log.Fatal("Cannot parse debug flag", err)
Expand Down
35 changes: 3 additions & 32 deletions config/parser.go
Expand Up @@ -16,8 +16,11 @@ import (
)

const DashDir = "gh-dash"

const ConfigYmlFileName = "config.yml"

const ConfigYamlFileName = "config.yaml"

const DEFAULT_XDG_CONFIG_DIRNAME = ".config"

var validate *validator.Validate
Expand Down Expand Up @@ -324,38 +327,6 @@ func (parser ConfigParser) createConfigFileIfMissing(
return nil
}

func (parser ConfigParser) getExistingConfigFile() (*string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, err
}

xdgConfigDir := os.Getenv("XDG_CONFIG_HOME")
if xdgConfigDir == "" {
xdgConfigDir = filepath.Join(homeDir, DEFAULT_XDG_CONFIG_DIRNAME)
}

configPaths := []string{
os.Getenv(
"GH_DASH_CONFIG",
), // If GH_DASH_CONFIG is empty, the os.Stat call fails
filepath.Join(xdgConfigDir, DashDir, ConfigYmlFileName),
filepath.Join(xdgConfigDir, DashDir, ConfigYamlFileName),
}

// Check if each config file exists, return the first one that does
for _, configPath := range configPaths {
if configPath == "" {
continue // Skip checking if path is empty
}
if _, err := os.Stat(configPath); err == nil {
return &configPath, nil
}
}

return nil, nil
}

func (parser ConfigParser) getDefaultConfigFileOrCreateIfMissing() (string, error) {
var configFilePath string

Expand Down

0 comments on commit 1c3c0a7

Please sign in to comment.