From 37e28ca0e1060145aa3fdb2fab92524cf9da074e Mon Sep 17 00:00:00 2001 From: toughnoah Date: Wed, 28 Jul 2021 20:43:24 +0800 Subject: [PATCH 1/2] fix snapshot flag completion --- Makefile | 1 + cmd/snapshot.go | 1 + pkg/util/decoder.go | 11 ----------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 448c196..742457c 100644 --- a/Makefile +++ b/Makefile @@ -32,3 +32,4 @@ install: ## build blackbean. clean: ## Remove test report. @rm -f *.out + diff --git a/cmd/snapshot.go b/cmd/snapshot.go index e2367ee..31f4924 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -171,6 +171,7 @@ func restoreSnapshot(cli *elasticsearch.Client, out io.Writer) *cobra.Command { _ = command.MarkFlagRequired("index") _ = command.MarkFlagRequired("rename_pattern") _ = command.MarkFlagRequired("rename_replacement") + _ = command.MarkFlagRequired("snapshot") return command } diff --git a/pkg/util/decoder.go b/pkg/util/decoder.go index 8ec6a01..0f98750 100644 --- a/pkg/util/decoder.go +++ b/pkg/util/decoder.go @@ -59,17 +59,6 @@ func Unmarshal(data []byte, v interface{}) error { } } -//// ToJSON converts a single YAML document into a JSON document -//// or returns an error. If the document appears to be JSON the -//// YAML decoding path is not used (so that error messages are -//// JSON specific). -//func ToJSON(data []byte) ([]byte, error) { -// if hasJSONPrefix(data) { -// return data, nil -// } -// return yaml.YAMLToJSON(data) -//} - // YAMLToJSONDecoder decodes YAML documents from an io.Reader by // separating individual documents. It first converts the YAML // body to JSON, then unmarshals the JSON. From ec40d10e345ce3607664317f0f30355db9404f26 Mon Sep 17 00:00:00 2001 From: toughnoah Date: Wed, 28 Jul 2021 20:47:47 +0800 Subject: [PATCH 2/2] fix snapshot flag completion --- cmd/snapshot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/snapshot.go b/cmd/snapshot.go index 31f4924..de7861d 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -155,7 +155,7 @@ func restoreSnapshot(cli *elasticsearch.Client, out io.Writer) *cobra.Command { } ) f := command.Flags() - f.StringVar(&snapshots, "snapshot", "_all", "to get specific snapshot") + f.StringVar(&snapshots, "snapshot", "", "to get specific snapshot") err := command.RegisterFlagCompletionFunc("snapshot", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 1 { return so.getRepoAllSnapshotsForFlag(args[0]), cobra.ShellCompDirectiveNoFileComp