From 3ccc7e4067c47f14868a4ce956e50dde79555a68 Mon Sep 17 00:00:00 2001 From: MOREV Mikhail Date: Mon, 13 Jan 2020 15:00:33 +0600 Subject: [PATCH] Fix destination path on single file publish --- cmd/sops/main.go | 1 + cmd/sops/subcommand/publish/publish.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/sops/main.go b/cmd/sops/main.go index 83393af20..6c138dc48 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -263,6 +263,7 @@ func main() { InputStore: inputStore(c, subPath), Interactive: !c.Bool("yes"), OmitExtensions: c.Bool("omit-extensions"), + Recursive: c.Bool("recursive"), }) if cliErr, ok := err.(*cli.ExitError); ok && cliErr != nil { return cliErr diff --git a/cmd/sops/subcommand/publish/publish.go b/cmd/sops/subcommand/publish/publish.go index fa7dba8cf..408c50621 100644 --- a/cmd/sops/subcommand/publish/publish.go +++ b/cmd/sops/subcommand/publish/publish.go @@ -34,6 +34,7 @@ type Opts struct { KeyServices []keyservice.KeyServiceClient InputStore sops.Store OmitExtensions bool + Recursive bool } // Run publish operation @@ -51,7 +52,13 @@ func Run(opts Opts) error { if conf.Destination == nil { return errors.New("no destination configured for this file") } - destinationPath := opts.InputPath + + var destinationPath string + if opts.Recursive { + destinationPath = opts.InputPath + } else { + _, destinationPath = filepath.Split(path) + } if opts.OmitExtensions || conf.OmitExtensions { destinationPath = strings.TrimSuffix(destinationPath, filepath.Ext(path)) } @@ -150,7 +157,13 @@ func Run(opts Opts) error { } } if response == "n" { - return errors.New("Publish canceled") + msg := fmt.Sprintf("Publication of %s canceled", path) + if opts.Recursive { + fmt.Println(msg) + return nil + } else { + return errors.New(msg) + } } }