diff --git a/cmd/challenge/catalog.go b/cmd/challenge/catalog.go index abe4801..fcbd29b 100644 --- a/cmd/challenge/catalog.go +++ b/cmd/challenge/catalog.go @@ -12,14 +12,15 @@ import ( ) type catalogOptions struct { - category string + category []string + status []string } func newCatalogCommand(cli labcli.CLI) *cobra.Command { var opts catalogOptions cmd := &cobra.Command{ - Use: "catalog [--category ]", + Use: "catalog [--category ] --status ", Aliases: []string{"catalog"}, Short: "List challenges from the catalog, optionally filtered by category", Args: cobra.NoArgs, @@ -30,11 +31,18 @@ func newCatalogCommand(cli labcli.CLI) *cobra.Command { flags := cmd.Flags() - flags.StringVar( + flags.StringSliceVar( &opts.category, "category", - "", - `Category to filter by - one of linux, containers, kubernetes, ... (an empty string means all)`, + []string{}, + `Category to filter by - one or multiple categories like linux, containers, kubernetes`, + ) + + flags.StringSliceVar( + &opts.status, + "status", + []string{}, + `status to filter by - one or multiple status like todo, attempted, solved)`, ) return cmd @@ -54,6 +62,7 @@ type catalogItem struct { func runCatalogChallenges(ctx context.Context, cli labcli.CLI, opts *catalogOptions) error { challenges, err := cli.Client().ListChallenges(ctx, &api.ListChallengesOptions{ Category: opts.category, + Status: opts.status, }) if err != nil { return fmt.Errorf("cannot list challenges: %w", err) diff --git a/internal/api/challenges.go b/internal/api/challenges.go index 39d4ff3..8e17506 100644 --- a/internal/api/challenges.go +++ b/internal/api/challenges.go @@ -109,15 +109,22 @@ func (c *Client) GetChallenge(ctx context.Context, name string) (*Challenge, err } type ListChallengesOptions struct { - Category string + Category []string + Status []string } func (c *Client) ListChallenges(ctx context.Context, opts *ListChallengesOptions) ([]*Challenge, error) { var challenges []*Challenge query := url.Values{} - if opts.Category != "" { - query.Set("category", opts.Category) + + for _, category := range opts.Category { + query.Add("category", category) } + + for _, status := range opts.Status { + query.Add("status", status) + } + return challenges, c.GetInto(ctx, "/challenges", query, nil, &challenges) }