Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ $ metalctlv2 ctx add <context-name> --activate --default-project <project-uuid>
```

The configuration file is by default written to `~/.metal-stack/config.yaml`.

## Environment Variables

All flags can also be provided as environment variables prefixed with `METAL_STACK_`. The flag name is uppercased and dashes are replaced by underscores, e.g. `--api-url` becomes `METAL_STACK_API_URL`.

An explicitly provided flag takes precedence over an environment variable, which in turn takes precedence over the context in `~/.metal-stack/config.yaml`.
2 changes: 1 addition & 1 deletion cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
// BinaryName is the name of the cli in all help texts
BinaryName = "metalctlv2"
// ConfigDir is the directory in either the homedir or in /etc where the cli searches for a file config.yaml
// also used as prefix for environment based configuration, e.g. METAL_STACK_CLOUD_ will be the variable prefix.
// also used as prefix for environment based configuration, e.g. METAL_STACK_ will be the variable prefix.
ConfigDir = "metal-stack"
)

Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"log/slog"
"os"
"strings"

client "github.com/metal-stack/api/go/client"
"github.com/metal-stack/metal-lib/pkg/genericcli"
Expand Down Expand Up @@ -42,6 +43,10 @@ func Execute() {
}

func NewRootCmd(c *config.Config) *cobra.Command {
viper.SetEnvPrefix(strings.ToUpper(config.ConfigDir))
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()

rootCmd := &cobra.Command{
Use: config.BinaryName,
Aliases: []string{"m"},
Expand Down
Loading