From 6550468048004101cebb967a8713556831afbe6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sat, 23 Mar 2024 15:43:11 -0700 Subject: [PATCH] only read identity/recipient files if none have been supplied via cli flags actually this time --- cmd/agedit/cli.go | 6 ++++-- cmd/agedit/main.go | 17 +++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/agedit/cli.go b/cmd/agedit/cli.go index cfb8b90..bf8e87f 100644 --- a/cmd/agedit/cli.go +++ b/cmd/agedit/cli.go @@ -60,6 +60,7 @@ var ( identities = append(identities, id) } + gave_identities = true return nil }, }, @@ -87,6 +88,7 @@ var ( } recipients = append(recipients, r) } + gave_recipients = true return nil }, }, @@ -204,7 +206,7 @@ func action(ctx *cli.Context) error { } // read from identity file if exists and no identities have been supplied - if len(identities) == 0 { + if !gave_identities { if _, err := os.Stat(cfg.IdentityFile); os.IsNotExist(err) { return fmt.Errorf("identity file unset and no identities supplied, use -i to specify an idenitity file or set one in the config file, or use -I to specify an age private key") } else { @@ -221,7 +223,7 @@ func action(ctx *cli.Context) error { } // read from recipient file if it exists and no recipients have been supplied - if len(recipients) == 0 { + if !gave_recipients && cfg.RecipientFile != "" { if _, err := os.Stat(cfg.RecipientFile); os.IsNotExist(err) { return fmt.Errorf("recipient file doesn't exist") } else { diff --git a/cmd/agedit/main.go b/cmd/agedit/main.go index eb3a2aa..5ed78a2 100644 --- a/cmd/agedit/main.go +++ b/cmd/agedit/main.go @@ -12,14 +12,15 @@ import ( ) var ( - identities []age.Identity - recipients []age.Recipient - logger *log.Logger - cfg config.Config - edt editor.Editor - configFile string - input_file, output_file string - force_overwrite bool + identities []age.Identity + recipients []age.Recipient + logger *log.Logger + cfg config.Config + edt editor.Editor + configFile string + input_file, output_file string + force_overwrite bool + gave_identities, gave_recipients bool ) func main() {