From e96bac3d9dc148b0550f9c3f1590871815dbd68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Fri, 22 Mar 2024 10:59:49 -0700 Subject: [PATCH] add force flag to re-encrypt even if data hasn't changed --- cmd/agedit/cli.go | 12 +++++++++++- cmd/agedit/main.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/agedit/cli.go b/cmd/agedit/cli.go index 875750b..f824913 100644 --- a/cmd/agedit/cli.go +++ b/cmd/agedit/cli.go @@ -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 } diff --git a/cmd/agedit/main.go b/cmd/agedit/main.go index 91d7d91..6d47e79 100644 --- a/cmd/agedit/main.go +++ b/cmd/agedit/main.go @@ -17,6 +17,7 @@ var ( configFile string input_file, output_file string + force_overwrite bool ) func main() {