From d3cf0e5715c4173c4f7b7c6640624a85f5b51118 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 20:58:56 +0800 Subject: [PATCH 1/3] refactor: hide `--output` flags that don't work --- x/auth/client/cli/decode.go | 1 + x/auth/client/cli/encode.go | 1 + x/auth/client/cli/tx_multisign.go | 9 ++++----- x/genutil/client/cli/gentx.go | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 72a8a600ce73..170e1fef2dce 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 0a04c7c21665..65a13c6d1ae5 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 747c1f09a143..209138cde366 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -61,6 +61,7 @@ The SIGN_MODE_DIRECT sign mode is not supported.' cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) return cmd } @@ -182,8 +183,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) if outputDoc == "" { - cmd.Printf("%s\n", json) - return nil + return clientCtx.PrintString(fmt.Sprintf("%s\n", json)) } fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) @@ -198,9 +198,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { } }() - err = clientCtx.PrintBytes(json) - - return err + return clientCtx.PrintBytes(json) } } @@ -235,6 +233,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 ce1b91e08e58..7c5ee6f7f9a7 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -216,6 +216,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o cmd.Flags().String(flags.FlagOutputDocument, "", "Write the genesis transaction JSON document to the given file instead of the default location") cmd.Flags().AddFlagSet(fsCreateValidator) flags.AddTxFlagsToCmd(cmd) + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json return cmd } From bc7e90f7b43618b80d88bda9e07f17061a7c2008 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Sat, 29 Jul 2023 23:07:43 +0800 Subject: [PATCH 2/3] refactor: use `setOutputFile` --- x/auth/client/cli/tx_multisign.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 209138cde366..b033b646f3e5 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -181,24 +181,15 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { return err } - outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - if outputDoc == "" { - return clientCtx.PrintString(fmt.Sprintf("%s\n", json)) - } - - 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 - } - }() + defer closeFunc() - return clientCtx.PrintBytes(json) + cmd.Printf("%s\n", json) + return nil } } From 58b55b6375c3b763660d73f9f150766d45a100a9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 30 Jul 2023 01:39:03 +0200 Subject: [PATCH 3/3] lint --- x/auth/client/cli/decode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 170e1fef2dce..2d49806b1244 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -48,7 +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 + _ = cmd.Flags().MarkHidden(flags.FlagOutput) // decoding makes sense to output only json return cmd }