diff --git a/cmd/sops/main.go b/cmd/sops/main.go index 72ef6a153e..f72e1dc115 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -716,6 +716,10 @@ func main() { Name: "output", Usage: "Save the output after encryption or decryption to the file specified", }, + cli.StringFlag{ + Name: "filename-override", + Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type", + }, }, keyserviceFlags...) app.Action = func(c *cli.Context) error { @@ -741,13 +745,17 @@ func main() { return common.NewExitError("Error: cannot operate on non-existent file", codes.NoFileSpecified) } } + fileNameOverride := c.String("filename-override") + if fileNameOverride == "" { + fileNameOverride = fileName + } unencryptedSuffix := c.String("unencrypted-suffix") encryptedSuffix := c.String("encrypted-suffix") encryptedRegex := c.String("encrypted-regex") unencryptedRegex := c.String("unencrypted-regex") macOnlyEncrypted := c.Bool("mac-only-encrypted") - conf, err := loadConfig(c, fileName, nil) + conf, err := loadConfig(c, fileNameOverride, nil) if err != nil { return toExitError(err) } @@ -793,19 +801,19 @@ func main() { unencryptedSuffix = sops.DefaultUnencryptedSuffix } - inputStore := inputStore(c, fileName) - outputStore := outputStore(c, fileName) + inputStore := inputStore(c, fileNameOverride) + outputStore := outputStore(c, fileNameOverride) svcs := keyservices(c) var output []byte if c.Bool("encrypt") { var groups []sops.KeyGroup - groups, err = keyGroups(c, fileName) + groups, err = keyGroups(c, fileNameOverride) if err != nil { return toExitError(err) } var threshold int - threshold, err = shamirThreshold(c, fileName) + threshold, err = shamirThreshold(c, fileNameOverride) if err != nil { return toExitError(err) } @@ -961,12 +969,12 @@ func main() { } else { // File doesn't exist, edit the example file instead var groups []sops.KeyGroup - groups, err = keyGroups(c, fileName) + groups, err = keyGroups(c, fileNameOverride) if err != nil { return toExitError(err) } var threshold int - threshold, err = shamirThreshold(c, fileName) + threshold, err = shamirThreshold(c, fileNameOverride) if err != nil { return toExitError(err) }