-
Notifications
You must be signed in to change notification settings - Fork 183
feat(user): add fuzzy, match, range flags for commands #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mujib-Ahasan
wants to merge
8
commits into
goharbor:main
Choose a base branch
from
Mujib-Ahasan:new-query-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2175f66
feat(user): add fuzzy,match,range flag for user list command
Mujib-Ahasan 13e5204
refractor: add fuzzy,match,range flags for resource query
Mujib-Ahasan 9acc3ce
New query flags added to few list subcommands
Mujib-Ahasan 7377fec
New query flags added to list scanners subcommand
Mujib-Ahasan 82f30b1
new query flags added to robot list
Mujib-Ahasan 166e882
fix: error handling and small nits
Mujib-Ahasan cbc32f9
fix: error handling
Mujib-Ahasan d519831
proper error handling added
Mujib-Ahasan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,14 @@ import ( | |
|
|
||
| // ListRobotCommand creates a new `harbor project robot list` command | ||
| func ListRobotCommand() *cobra.Command { | ||
| var opts api.ListFlags | ||
|
|
||
| var ( | ||
| opts api.ListFlags | ||
| // For querying, opts.Q | ||
| fuzzy []string | ||
| match []string | ||
| ranges []string | ||
| ) | ||
|
|
||
| projectQString := constants.ProjectQString | ||
| cmd := &cobra.Command{ | ||
|
|
@@ -102,6 +109,19 @@ Examples: | |
| opts.Q = projectQString + strconv.FormatInt(projectID, 10) | ||
| } | ||
|
|
||
| if len(fuzzy) != 0 || len(match) != 0 || len(ranges) != 0 { | ||
| q, qErr := utils.BuildQueryParam(fuzzy, match, ranges, | ||
| []string{"id", "secret", "description", "name", "disable", "level", "duration", "editable"}, | ||
| ) | ||
| if qErr != nil { | ||
| return qErr | ||
| } | ||
| if opts.Q != "" { | ||
| opts.Q += "," | ||
| } | ||
| opts.Q += q | ||
|
Mujib-Ahasan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| robots, err := api.ListRobot(opts) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get robots list: %v", utils.ParseHarborErrorMsg(err)) | ||
|
|
@@ -126,13 +146,10 @@ Examples: | |
| flags.Int64VarP(&opts.PageSize, "page-size", "", 10, "Size of per page") | ||
| flags.Int64VarP(&opts.ProjectID, "project-id", "", 0, "Project ID") | ||
| flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources") | ||
|
Comment on lines
147
to
148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No query conversion here |
||
| flags.StringVarP( | ||
| &opts.Sort, | ||
| "sort", | ||
| "", | ||
| "", | ||
| "Sort the resource list in ascending or descending order", | ||
| ) | ||
| flags.StringSliceVar(&fuzzy, "fuzzy", nil, "Fuzzy match filter (key=value)") | ||
| flags.StringSliceVar(&match, "match", nil, "exact match filter (key=value)") | ||
| flags.StringSliceVar(&ranges, "range", nil, "range filter (key=min~max)") | ||
| flags.StringVarP(&opts.Sort, "sort", "", "", "Sort the resource list in ascending or descending order") | ||
|
|
||
| return cmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.