Skip to content

Commit

Permalink
Fix --config being ignored by loadConfig
Browse files Browse the repository at this point in the history
Use `GlobalString` in `loadConfig` since `--config` is not a sub-command
flag.

This fixes `--config` being ignored and the CLI erroring out in a
maddening way.

FWIW here is how I got a debug build on Nix to debug this issue with
delve:

```
$ cat ~/snippets/sops-debug-build.nix
sops.overrideAttrs(final: prev: {
  ldflags = [ "-X github.com/getsops/sops/v3/version.Version=${prev.version}" ];
  GOFLAGS = prev.GOFLAGS ++ [ "'-gcflags=all=-N -l'" ];
  dontStrip = true;
})
$ nix-store --realise $(nix-instantiate ~/snippets/sops-debug-build.nix)
```
  • Loading branch information
lopter committed Sep 13, 2024
1 parent 422c397 commit d74876c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2178,10 +2178,8 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) {
// Since a config file is not required, this function does not error when one is not found, and instead returns a nil config pointer
func loadConfig(c *cli.Context, file string, kmsEncryptionContext map[string]*string) (*config.Config, error) {
var err error
var configPath string
if c.String("config") != "" {
configPath = c.String("config")
} else {
configPath := c.GlobalString("config")
if configPath == "" {
// Ignore config not found errors returned from FindConfigFile since the config file is not mandatory
configPath, err = config.FindConfigFile(".")
if err != nil {
Expand Down

0 comments on commit d74876c

Please # to comment.