diff --git a/cmd/servicelog/common.go b/cmd/servicelog/common.go index 6168839d..4b9410a6 100644 --- a/cmd/servicelog/common.go +++ b/cmd/servicelog/common.go @@ -36,7 +36,7 @@ func createConnection() *sdk.Connection { // generateQuery returns an OCM search query to retrieve all clusters matching an expression (ie- "foo%") func generateQuery(clusterIdentifier string) string { - return strings.TrimSpace(fmt.Sprintf("id like '%[1]s' or external_id like '%[1]s' or display_name like '%[1]s'", clusterIdentifier)) + return strings.TrimSpace(fmt.Sprintf("(id like '%[1]s' or external_id like '%[1]s' or display_name like '%[1]s')", clusterIdentifier)) } // getFilteredClusters retrieves clusters in OCM which match the filters given @@ -51,6 +51,9 @@ func applyFilters(ocmClient *sdk.Connection, filters []string) ([]*v1.Cluster, e requestSize := 50 full_filters := strings.Join(filters, " and ") + + log.Infof(`running the command: 'ocm list clusters --parameter=search="%s"'`, full_filters) + request := ocmClient.ClustersMgmt().V1().Clusters().List().Search(full_filters).Size(requestSize) response, err := request.Send() if err != nil { diff --git a/cmd/servicelog/list.go b/cmd/servicelog/list.go index 9ea1f247..92431c50 100644 --- a/cmd/servicelog/list.go +++ b/cmd/servicelog/list.go @@ -20,7 +20,7 @@ var listCmd = &cobra.Command{ Args: cobra.ArbitraryArgs, SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { - if len(args) != 1 { + if len(args) == 0 { cmd.Help() return fmt.Errorf("cluster-identifier was not provided. please provide a cluster id, UUID, or name") } diff --git a/cmd/servicelog/post.go b/cmd/servicelog/post.go index e08c114c..7f83ff64 100644 --- a/cmd/servicelog/post.go +++ b/cmd/servicelog/post.go @@ -51,7 +51,7 @@ var postCmd = &cobra.Command{ readFilterFile() // parse the ocm filters in file provided via '-f' flag readTemplate() // parse the given JSON template provided via '-t' flag - if len(args) < 1 && filtersFromFile == "" && clustersFile == "" { + if len(args) == 0 && len(filterParams) == 0 && clustersFile == "" { log.Fatalf("No cluster identifier has been found.") } @@ -108,7 +108,7 @@ var postCmd = &cobra.Command{ cluster := ClustersFile.Clusters[i] query = append(query, generateQuery(cluster)) } - filterParams = query + filterParams = append(filterParams, strings.Join(query, " or ")) } clusters, err := applyFilters(ocmClient, filterParams) @@ -180,7 +180,7 @@ func init() { postCmd.Flags().StringArrayVarP(&filterParams, "query", "q", filterParams, "Specify a search query (eg. -q \"name like foo\") for a bulk-post to matching clusters.") postCmd.Flags().BoolVarP(&skipPrompts, "yes", "y", false, "Skips all prompts.") postCmd.Flags().StringArrayVarP(&filterFiles, "query-file", "f", filterFiles, "File containing search queries to apply. All lines in the file will be concatenated into a single query. If this flag is called multiple times, every file's search query will be combined with logical AND.") - postCmd.Flags().StringVarP(&clustersFile, "clusters-file", "c", clustersFile, "Read a list of clusters to post the servicelog to") + postCmd.Flags().StringVarP(&clustersFile, "clusters-file", "c", clustersFile, `Read a list of clusters to post the servicelog to. the format of the file is: {"clusters":["$CLUSTERID"]}`) } // parseUserParameters parse all the '-p FOO=BAR' parameters and checks for syntax errors