Skip to content

feat(user): add fuzzy, match, range flags for commands#682

Open
Mujib-Ahasan wants to merge 8 commits into
goharbor:mainfrom
Mujib-Ahasan:new-query-flags
Open

feat(user): add fuzzy, match, range flags for commands#682
Mujib-Ahasan wants to merge 8 commits into
goharbor:mainfrom
Mujib-Ahasan:new-query-flags

Conversation

@Mujib-Ahasan
Copy link
Copy Markdown

Description

Only harbor-cli project list and harbor-cli label list support fuzzy, match, and range flags. All the other commands does not follow this way to query resource.
This PR has been raised to make fuzzy, match, range flag available to other required commands(eg: user, artifact, instance, registry etc).

Resolves #674

@Mujib-Ahasan
Copy link
Copy Markdown
Author

Hello @NucleoFusion, this is yet to be tested, but I am really confused to find the keys to be used in list subcommands. Changes have been made for user list command for now. Could you please help me to get the keys for other commands?!

@NucleoFusion
Copy link
Copy Markdown
Contributor

@Mujib-Ahasan the keys are the fields/keys in the JSON object they return. They are available on the demo.goharbor.io swagger api

@Mujib-Ahasan
Copy link
Copy Markdown
Author

Great, Thank you @NucleoFusion!

@Mujib-Ahasan
Copy link
Copy Markdown
Author

@NucleoFusion , PTAL at these changes. after that I will do some tests against my local setup.

@NucleoFusion
Copy link
Copy Markdown
Contributor

@Mujib-Ahasan

  • Repositories
    • All Repo's
    • Project Repositories
  • Artifacts
  • Tags
  • Accessories
  • Auditlogs
  • Preheat
    • instances
    • policies
    • executions
    • execution tasks
  • Immutable Tag Rules
  • Webhooks
    • policies
    • execs
    • execution tasks
  • Robots
  • Replication
    • policies
    • executions
    • execution tasks
  • Registries
  • Scanner
  • Users
  • Labels
  • SecurityHub - Vuln List

All these are supported via the q param as per the swagger API. Can you make a checklist and check if they all are implemented as the q param.
And if they are not present in the CLI as of now, please mention the same

@Mujib-Ahasan
Copy link
Copy Markdown
Author

Mujib-Ahasan commented Feb 11, 2026

  • Repositories (--query)
    • All Repos
    • Project Repositories
  • Artifacts (--query)
  • Tags ( No CLI)
  • Immutable Tags Rule (CLI implemented, --query not present)
  • Accessories (No CLI)
  • Auditlogs (--query)
  • Preheat
    • instances (--query)
    • policies (No CLI)
    • executions (No CLI)
    • execution tasks (No CLI)
  • Webhooks
    • policies(CLI implemented, --query not present)
    • execs (No CLI)
    • execution tasks (No CLI)
  • Robots (--query)
  • Replication
    • policies (--query)
    • executions (--query)
    • execution tasks (No CLI)
  • Registries (--query)
  • Scanner(CLI implemented, --query not present)
  • Users (--query)
  • Labels )--query)
  • SecurityHub - Vuln List(No CLI)

(only for list subcommand)

@NucleoFusion PTAL.

@NucleoFusion
Copy link
Copy Markdown
Contributor

Have you done all those? In the checklist that have CLI present?
If so I will have a look ASAP

@Mujib-Ahasan
Copy link
Copy Markdown
Author

I did only for those which has --query flag (--query in the bracket in my prev comment) . I have not worked in CLI which do not have --query flag ( ex:- https://github.com/goharbor/harbor-cli/blob/main/cmd/harbor/root/webhook/list.go).

@NucleoFusion
Copy link
Copy Markdown
Contributor

NucleoFusion commented Feb 22, 2026

Sorry for the delay.
I can see that even though some of the CLI Commands dont have --query builtin, but their API in Harbor does support it.
For example,

tags/immutable/list.go, artifact/tags.go

image image

The list I have given has all the endpoints that support q param as per the API. not the CLI.
Please check and add to even those that done have the --query currently.
@Mujib-Ahasan

@Mujib-Ahasan
Copy link
Copy Markdown
Author

Changes have been made. Ready for the review @NucleoFusion!

Comment on lines 116 to 117
flags.Int64VarP(&opts.ProjectID, "project-id", "", 0, "Project ID")
flags.StringVarP(&opts.Q, "query", "q", "", "Query string to query resources")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No query conversion here

Copy link
Copy Markdown
Contributor

@NucleoFusion NucleoFusion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@qcserestipy
Copy link
Copy Markdown
Collaborator

Please fix merge conflicts for this PR to be merged

@Mujib-Ahasan
Copy link
Copy Markdown
Author

@qcserestipy PTAL. you can proceed with the merge now.

@bupd bupd requested review from bupd and Copilot April 7, 2026 13:25
@bupd bupd self-assigned this Apr 7, 2026
@bupd bupd added enhancement New feature or request go Pull requests that update go code labels Apr 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 0% with 348 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.62%. Comparing base (60ad0bd) to head (52c9f28).
⚠️ Report is 131 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/artifact/tags.go 0.00% 113 Missing ⚠️
cmd/harbor/root/scanner/list.go 0.00% 20 Missing ⚠️
cmd/harbor/root/project/robot/list.go 0.00% 19 Missing ⚠️
cmd/harbor/root/tag/immutable/list.go 0.00% 19 Missing ⚠️
cmd/harbor/root/webhook/list.go 0.00% 19 Missing ⚠️
cmd/harbor/root/robot/list.go 0.00% 18 Missing ⚠️
cmd/harbor/root/artifact/list.go 0.00% 17 Missing ⚠️
cmd/harbor/root/user/list.go 0.00% 17 Missing ⚠️
cmd/harbor/root/instance/list.go 0.00% 16 Missing ⚠️
cmd/harbor/root/registry/list.go 0.00% 16 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #682      +/-   ##
=========================================
- Coverage   10.99%   7.62%   -3.38%     
=========================================
  Files         173     271      +98     
  Lines        8671   13477    +4806     
=========================================
+ Hits          953    1027      +74     
- Misses       7612   12337    +4725     
- Partials      106     113       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds fuzzy, match, and range flags to multiple Harbor CLI commands for more user-friendly query filtering. Instead of using the old --query parameter format, users can now use intuitive flags like --fuzzy name=value, --match key=value, and --range key=min~max. The changes include updates to API handler functions to accept optional ListFlags parameters and corresponding command implementations to build query strings from the new flag inputs.

Changes:

  • Updated 13 API handler functions to accept optional ListFlags parameters
  • Added fuzzy, match, and range flags to 14 command implementations
  • Created new artifact/tags.go command file with full flag support
  • Reformatted multi-line flag definitions in quota/list.go and robot/list.go

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/api/webhook_handler.go Updated ListWebhooks() to accept optional ListFlags
pkg/api/scanner_handler.go Updated ListScanners() to accept optional ListFlags
pkg/api/immutable_handler.go Updated ListImmutable() to accept optional ListFlags
pkg/api/artifact_handler.go Updated ListTags() to accept optional ListFlags
cmd/harbor/root/webhook/list.go Added fuzzy, match, range flags
cmd/harbor/root/user/list.go Added fuzzy, match, range flags
cmd/harbor/root/tag/immutable/list.go Added fuzzy, match, range flags
cmd/harbor/root/scanner/list.go Added fuzzy, match, range flags
cmd/harbor/root/robot/list.go Added fuzzy, match, range flags
cmd/harbor/root/repository/list.go Added fuzzy, match, range flags
cmd/harbor/root/replication/policies/list.go Added fuzzy, match, range flags
cmd/harbor/root/replication/executions/list.go Added fuzzy, match, range flags
cmd/harbor/root/registry/list.go Added fuzzy, match, range flags
cmd/harbor/root/quota/list.go Reformatted multi-line flag definition
cmd/harbor/root/project/robot/list.go Added fuzzy, match, range flags
cmd/harbor/root/instance/list.go Added fuzzy, match, range flags
cmd/harbor/root/artifact/tags.go New file with tag listing command supporting query flags
cmd/harbor/root/artifact/list.go Added fuzzy, match, range flags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/instance/list.go
Comment thread cmd/harbor/root/replication/executions/list.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/scanner/list.go
Comment thread cmd/harbor/root/tag/immutable/list.go
Comment thread cmd/harbor/root/webhook/list.go
Comment thread cmd/harbor/root/project/robot/list.go
Comment thread cmd/harbor/root/instance/list.go
Comment thread cmd/harbor/root/artifact/list.go
Comment thread cmd/harbor/root/artifact/tags.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/robot/list.go
@Mujib-Ahasan
Copy link
Copy Markdown
Author

Hey @bupd, PTAL, whenever you get time!

Copy link
Copy Markdown
Member

@bupd bupd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mujib-Ahasan Thanks for your contribution, Please fix CI and also rebase your commits and resolve conflicts.

@bupd bupd added the Changes Requesed feedback that must be addressed before merging. label May 19, 2026
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (5)

cmd/harbor/root/webhook/list.go:94

  • If an output format is requested, the command prints formatted output but then still proceeds to render the interactive table view. This results in double output (and potentially breaks machine-readable output). Consider returning immediately after PrintFormat or moving the table rendering into an else branch.
			FormatFlag := viper.GetString("output-format")
			if FormatFlag != "" {
				err = utils.PrintFormat(resp, FormatFlag)
				if err != nil {
					return fmt.Errorf("failed to print in %s format: %v", FormatFlag, err)
				}
			}
			webhookViews.ListWebhooks(resp.Payload)
			return nil

cmd/harbor/root/tag/immutable/list.go:78

  • Typo in the error message: "immutablility" should be "immutability".
				return fmt.Errorf("failed to list immutablility rule: %v", err)

cmd/harbor/root/replication/policies/list.go:70

  • This error message says "failed to get projects list" but this command is listing replication policies, which makes the message misleading. Consider updating it to mention replication policies.
			if err != nil {
				return fmt.Errorf("failed to get projects list: %v", utils.ParseHarborErrorMsg(err))
			}

cmd/harbor/root/replication/executions/list.go:85

  • This error message says "failed to get projects list" but this command is listing replication executions. Consider updating the message to reference replication executions (and possibly include the policy ID).
			if err != nil {
				return fmt.Errorf("failed to get projects list: %v", utils.ParseHarborErrorMsg(err))
			}

cmd/harbor/root/registry/list.go:68

  • This error message says "failed to get projects list" but this command is listing registries, which is misleading. Consider updating it to mention registries.
			registry, err := api.ListRegistries(opts)

			if err != nil {
				return fmt.Errorf("failed to get projects list: %v", err)
			}

Comment thread cmd/harbor/root/user/list.go
Comment thread cmd/harbor/root/scanner/list.go
Comment thread cmd/harbor/root/robot/list.go
Comment thread cmd/harbor/root/repository/list.go
Comment thread cmd/harbor/root/replication/policies/list.go
Comment thread cmd/harbor/root/replication/executions/list.go
Comment thread cmd/harbor/root/registry/list.go
Comment thread cmd/harbor/root/instance/list.go
Comment thread cmd/harbor/root/artifact/list.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requesed feedback that must be addressed before merging. enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Refactor old commands that support the q query paramater to now utilize the new format.

5 participants