Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cmd/kosli/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -17,15 +18,18 @@ type configOptions struct {
unSetKeys []string
}

const configShortDesc = `Config global Kosli flags values and store them in $HOME/.kosli . `
const configShortDesc = `Config global Kosli flags values and store them in $HOME/.kosli.yml . `

const configLongDesc = configShortDesc + `

Flag values are determined in the following order (highest precedence first):
- command line flags on each executed command.
- environment variables.
- custom config file provided with --config-file flag.
- default config file in $HOME/.kosli
- custom config file provided with the --config-file flag or the KOSLI_CONFIG_FILE env var.
- default config file in $HOME/.kosli.yml

A config file in the directory a command runs from is never read unless it is named
with --config-file or KOSLI_CONFIG_FILE.

You can configure global Kosli flags (the ones that apply to all/most commands) using their dedicated
convenience flags (e.g. --org).
Expand Down Expand Up @@ -79,6 +83,12 @@ func newConfigCmd(out io.Writer) *cobra.Command {

func (o *configOptions) run() error {
path := defaultConfigFilePathFunc()
// An empty path means no home directory could be resolved. Continuing would
// write the config into the current working directory, which is never where
// the default config file belongs.
if path == "" {
Comment thread
pbeckham marked this conversation as resolved.
return errors.New("setting default config failed. Could not determine your home directory. Set HOME, or pass --config-file to the commands you run")
}
home := filepath.Dir(path)
configFileName := filepath.Base(path)
permissions := os.FileMode(0600)
Expand Down
Loading
Loading