Skip to content

Commit

Permalink
Merge pull request ipfs#162 from ipfs/schomatis/feat/cmds/use-custom-…
Browse files Browse the repository at this point in the history
…config-file-path

feat(config): Filename(): allow changing config file path
  • Loading branch information
schomatis authored Mar 8, 2022
2 parents 8ff5edc + ea7b3a0 commit fe6f0c1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,23 @@ func Path(configroot, extension string) (string, error) {
}

// Filename returns the configuration file path given a configuration root
// directory. If the configuration root directory is empty, use the default one
func Filename(configroot string) (string, error) {
return Path(configroot, DefaultConfigFile)
// directory and a user-provided configuration file path argument with the
// following rules:
// * If the user-provided configuration file path is empty, use the default one.
// * If the configuration root directory is empty, use the default one.
// * If the user-provided configuration file path is only a file name, use the
// configuration root directory, otherwise use only the user-provided path
// and ignore the configuration root.
func Filename(configroot string, userConfigFile string) (string, error) {
if userConfigFile == "" {
return Path(configroot, DefaultConfigFile)
}

if filepath.Dir(userConfigFile) == "." {
return Path(configroot, userConfigFile)
}

return userConfigFile, nil
}

// HumanOutput gets a config value ready for printing
Expand Down

0 comments on commit fe6f0c1

Please sign in to comment.