Skip to content

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

@NucleoFusion

Description

@NucleoFusion

Most commands use the Q for querying a list of results. There format is very non-user friendly.

Query string to query resources. Supported query patterns are "exact match(k=v)", "fuzzy match(k=~v)", "range(k=[min~max])", "list with union releationship(k={v1 v2 v3})" and "list with intersetion relationship(k=(v1 v2 v3))". The value of range and list can be string(enclosed by " or '), integer or time(in format "2020-04-09 02:36:00"). All of these query patterns should be put in the query string "q=xxx" and splitted by ",". e.g. q=k1=v1,k2=~v2,k3=[min~max]

This is the official description.
Ex: name=~some,id=222
And in a command this would look like:-

harbor-cli user list --query name=~some,id=222

This is un-intuitive.

Instead for a more UX friendly approach we have a new solution in some of the commands. Which is,

harbor-cli user list --fuzzy name=some --match id=222 ---range <something>

And this is supported by,

func BuildQueryParam(fuzzy, match, ranges []string, validKeys []string) (string, error) {

In the pkg/utils/query.go.

With flag format like this,

	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)")

Although this is implemented for a few of the new commands, the old ones still rely on the outdated format.
We need to update them to be similar to the new ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions