From 6cb906ab5fbdf34d9cb1e1cbf086050b1f29812f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 11 Feb 2021 01:07:48 +0300 Subject: [PATCH] [#362] cli/object: Support JSON input of search filter Consider single word of search filter expression as path to file with protobuf JSON filters. Decode filters from file and add them to the rest. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/object.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index c1352971..e3d3442a 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -141,7 +141,7 @@ func init() { objectSearchCmd.Flags().String("cid", "", "Container ID") _ = objectSearchCmd.MarkFlagRequired("cid") objectSearchCmd.Flags().StringSliceVarP(&searchFilters, "filters", "f", nil, - "Repeated filter expressions") + "Repeated filter expressions or files with protobuf JSON") objectSearchCmd.Flags().Bool("root", false, "Search for user objects") objectSearchCmd.Flags().Bool("phy", false, "Search physically stored objects") objectSearchCmd.Flags().String(searchOIDFlag, "", "Search object by identifier") @@ -541,6 +541,19 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) { switch len(words) { default: return nil, fmt.Errorf("invalid field number: %d", len(words)) + case 1: + data, err := ioutil.ReadFile(words[0]) + if err != nil { + return nil, err + } + + subFs := object.NewSearchFilters() + + if err := subFs.UnmarshalJSON(data); err != nil { + return nil, err + } + + fs = append(fs, subFs...) case 2: m, ok := searchUnaryOpVocabulary[words[1]] if !ok {