From 991be5e443311fa986260cc85dada6829fddc3f9 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 8 Jan 2024 17:29:32 -0500 Subject: [PATCH 1/3] fix: output-document flag --- x/auth/client/cli/decode.go | 1 + x/auth/client/cli/encode.go | 1 + x/auth/client/cli/tx_multisign.go | 23 ++++++----------------- x/genutil/client/cli/gentx.go | 1 + 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 72a8a600ce73..2d49806b1244 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -48,6 +48,7 @@ func GetDecodeCommand() *cobra.Command { cmd.Flags().BoolP(flagHex, "x", false, "Treat input as hexadecimal instead of base64") flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // decoding makes sense to output only json return cmd } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index 6c1d66facdf9..3da38cf13c42 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -42,6 +42,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea } flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // encoding makes sense to output only json return cmd } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 7b196adc3c02..121725a9d3d5 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -65,7 +65,7 @@ The SIGN_MODE_DIRECT sign mode is not supported.' cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") cmd.Flags().Bool(flagAmino, false, "Generate Amino-encoded JSON suitable for submitting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) - cmd.Flags().String(flags.FlagChainID, "", "network chain ID") + _ = cmd.Flags().MarkHidden(flags.FlagOutput) return cmd } @@ -186,27 +186,15 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } } - outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - if outputDoc == "" { - cmd.Printf("%s\n", json) - return - } - - fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) + closeFunc, err := setOutputFile(cmd) if err != nil { return err } - defer func() { - err2 := fp.Close() - if err == nil { - err = err2 - } - }() - - err = clientCtx.PrintBytes(json) + defer closeFunc() - return + cmd.Printf("%s\n", json) + return nil } } @@ -240,6 +228,7 @@ The SIGN_MODE_DIRECT sign mode is not supported.' ) cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json return cmd } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 4880fa375503..c828b4c2d9af 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -212,6 +212,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") cmd.Flags().AddFlagSet(fsCreateValidator) flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json return cmd } From 026cdf70dfcaab73e9f7c56fe51b0c595ddcada4 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 8 Jan 2024 17:33:18 -0500 Subject: [PATCH 2/3] Revert "fix: output-document flag" This reverts commit 991be5e443311fa986260cc85dada6829fddc3f9. --- x/auth/client/cli/decode.go | 1 - x/auth/client/cli/encode.go | 1 - x/auth/client/cli/tx_multisign.go | 23 +++++++++++++++++------ x/genutil/client/cli/gentx.go | 1 - 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 2d49806b1244..72a8a600ce73 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -48,7 +48,6 @@ func GetDecodeCommand() *cobra.Command { cmd.Flags().BoolP(flagHex, "x", false, "Treat input as hexadecimal instead of base64") flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) // decoding makes sense to output only json return cmd } diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index 3da38cf13c42..6c1d66facdf9 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -42,7 +42,6 @@ If you supply a dash (-) argument in place of an input filename, the command rea } flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) // encoding makes sense to output only json return cmd } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 121725a9d3d5..7b196adc3c02 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -65,7 +65,7 @@ The SIGN_MODE_DIRECT sign mode is not supported.' cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") cmd.Flags().Bool(flagAmino, false, "Generate Amino-encoded JSON suitable for submitting to the txs REST endpoint") flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) + cmd.Flags().String(flags.FlagChainID, "", "network chain ID") return cmd } @@ -186,15 +186,27 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } } - closeFunc, err := setOutputFile(cmd) + outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) + if outputDoc == "" { + cmd.Printf("%s\n", json) + return + } + + fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) if err != nil { return err } - defer closeFunc() + defer func() { + err2 := fp.Close() + if err == nil { + err = err2 + } + }() - cmd.Printf("%s\n", json) - return nil + err = clientCtx.PrintBytes(json) + + return } } @@ -228,7 +240,6 @@ The SIGN_MODE_DIRECT sign mode is not supported.' ) cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json return cmd } diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index c828b4c2d9af..4880fa375503 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -212,7 +212,6 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") cmd.Flags().AddFlagSet(fsCreateValidator) flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json return cmd } From 5669548c17d1e417fc791bd5ad6bb64cc84b7d77 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 8 Jan 2024 17:36:25 -0500 Subject: [PATCH 3/3] fix: cherry pick just the fix --- x/auth/client/cli/tx_multisign.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 7b196adc3c02..d6826edf0d3d 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -186,27 +186,14 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } } - outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - if outputDoc == "" { - cmd.Printf("%s\n", json) - return - } - - fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) + closeFunc, err := setOutputFile(cmd) if err != nil { return err } - defer func() { - err2 := fp.Close() - if err == nil { - err = err2 - } - }() - - err = clientCtx.PrintBytes(json) - - return + defer closeFunc() + cmd.Printf("%s\n", json) + return nil } }