feat: suppport repo ls sub-namespace#768
Conversation
|
I have two design questions:
i.e. : currently the
currently: or |
|
I think the latter is out-of-option. Consider the scenario: How can the result of |
| hostname, namespace, _ := strings.Cut(args[0], "/") | ||
| opts.hostname = hostname | ||
| opts.namespace = namespace | ||
| // namespace is invalid if a tag is provided | ||
| if strings.Contains(namespace, ":") { | ||
| return fmt.Errorf("invalid namespace") | ||
| } |
There was a problem hiding this comment.
Can we refactor this part into a function so that we can unit test it?
There was a problem hiding this comment.
Parsing can be simplified in an easier way.
If args[0] contains /, we can parse it using ParseReference(). Otherwise, it is a hostname.
There was a problem hiding this comment.
Used ParseReference and created the function parseRepoPath to use in RunE.
| before, after, found := strings.Cut(repopath, requestedNamespace) | ||
| if !found || after == "" || before != "" { | ||
| return false | ||
| } | ||
| return after[0] == '/' |
There was a problem hiding this comment.
It partially works and is not readable. Can we choose a simpler implementation?
The reason why it partially works is that the inNamespace("foo", "foo") returns false, which should be true. You need unit tests to ensure code quality.
There was a problem hiding this comment.
It seems to be a UX issue other than a bug.
There was a problem hiding this comment.
Used strings.HasPrefix(repopath, opts.namespace+"/") here after discussion.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #768 +/- ##
==========================================
- Coverage 62.71% 55.86% -6.86%
==========================================
Files 20 23 +3
Lines 802 929 +127
==========================================
+ Hits 503 519 +16
- Misses 257 368 +111
Partials 42 42 ☔ View full report in Codecov by Sentry. |
This is a good question. I would suggest the latter one: $ oras repo ls example-registry/engineering
bestpractices
newhires/onboarding
newhires/teamoverviewIn this way, it is more consistent with the UNIX namespace=example-registry/engineering
oras repo ls $namespace | while read repo; do
repo=$namespace/$repo
echo Tags in $repo:
oras repo tags $repo
echo
done |
|
@wangxiaoxuan273 I vote for the latter one and agree with @shizhMSFT 's suggestion. |
Then |
| return cmd | ||
| } | ||
|
|
||
| func parseRepoPath(opts *repositoryOptions, arg string) error { |
There was a problem hiding this comment.
Can we add unit tests for this function?
There was a problem hiding this comment.
Added unit tests.
| return err | ||
| } | ||
| opts.hostname = reference.Registry | ||
| opts.namespace = reference.Repository |
There was a problem hiding this comment.
| opts.namespace = reference.Repository | |
| opts.namespace = reference.Repository + "/" |
so that we don't need to calculate it multiple time in a loop at line 96.
There was a problem hiding this comment.
changed accordingly.
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Resolves #733
Test output on terminal:

Signed-off-by: wangxiaoxuan273 wangxiaoxuan119@gmail.com