add force flag to re-encrypt even if data hasn't changed

This commit is contained in:
Lilian Jónsdóttir 2024-03-22 10:59:49 -07:00
parent 9c0c3ee788
commit e96bac3d9d
2 changed files with 12 additions and 1 deletions

View file

@ -66,6 +66,15 @@ var (
return nil
},
},
&cli.BoolFlag{
Name: "force",
Usage: "Re-encrypt the file even if no changes have been made.",
Aliases: []string{"f"},
Action: func(ctx *cli.Context, b bool) error {
force_overwrite = b
return nil
},
},
&cli.StringFlag{
Name: "log",
Usage: "log level",
@ -162,7 +171,8 @@ func action(ctx *cli.Context) error {
}
logger.Debug("got data back from editor")
if string(edited) == string(decrypted) {
// don't overwrite same data, unless specified
if string(edited) == string(decrypted) && !force_overwrite {
logger.Warn("No edits made, not writing " + output_file)
return nil
}

View file

@ -17,6 +17,7 @@ var (
configFile string
input_file, output_file string
force_overwrite bool
)
func main() {