1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Fix destination path on single file publish

This commit is contained in:
MOREV Mikhail
2020-01-13 15:00:33 +06:00
parent 01b5fb6279
commit 3ccc7e4067
2 changed files with 16 additions and 2 deletions

View File

@@ -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

View File

@@ -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)
}
}
}