From dbfb6fadd67197c292bb34dd474e1dcffe28a5d8 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 20 Nov 2020 11:08:40 +0300 Subject: [PATCH] [#177] cmd/neofs-cli: Add object ID filter flag to search cmd Add "oid" flag that allows to filter objects by identifier. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/object.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 53a647cae5..12d5cd0308 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -80,6 +80,8 @@ const ( rangeSep = ":" ) +const searchOIDFlag = "oid" + func init() { rootCmd.AddCommand(objectCmd) objectCmd.PersistentFlags().String("bearer", "", "File with signed JSON or binary encoded bearer token") @@ -114,6 +116,7 @@ func init() { objectSearchCmd.Flags().String("filters", "", "Filters in the form hdrName=value,...") 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") objectCmd.AddCommand(objectHeadCmd) objectHeadCmd.Flags().String("file", "", "File to write header to. Default: stdout.") @@ -460,6 +463,16 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) { fs.AddPhyFilter() } + oid, _ := cmd.Flags().GetString(searchOIDFlag) + if oid != "" { + id := object.NewID() + if err := id.Parse(oid); err != nil { + return nil, err + } + + fs.AddObjectIDFilter(object.MatchStringEqual, id) + } + return fs, nil }