[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-11 01:07:48 +03:00 committed by Leonard Lyubich
parent 6039cd119c
commit 6cb906ab5f

View file

@ -141,7 +141,7 @@ func init() {
objectSearchCmd.Flags().String("cid", "", "Container ID") objectSearchCmd.Flags().String("cid", "", "Container ID")
_ = objectSearchCmd.MarkFlagRequired("cid") _ = objectSearchCmd.MarkFlagRequired("cid")
objectSearchCmd.Flags().StringSliceVarP(&searchFilters, "filters", "f", nil, 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("root", false, "Search for user objects")
objectSearchCmd.Flags().Bool("phy", false, "Search physically stored objects") objectSearchCmd.Flags().Bool("phy", false, "Search physically stored objects")
objectSearchCmd.Flags().String(searchOIDFlag, "", "Search object by identifier") objectSearchCmd.Flags().String(searchOIDFlag, "", "Search object by identifier")
@ -541,6 +541,19 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) {
switch len(words) { switch len(words) {
default: default:
return nil, fmt.Errorf("invalid field number: %d", len(words)) 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: case 2:
m, ok := searchUnaryOpVocabulary[words[1]] m, ok := searchUnaryOpVocabulary[words[1]]
if !ok { if !ok {