Skip to content

Commit

Permalink
fix: update error message for repo ls (#1169)
Browse files Browse the repository at this point in the history
Signed-off-by: Sajay Antony <[email protected]>
  • Loading branch information
sajayantony authored Nov 6, 2023
1 parent 94e32e8 commit dbf40e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/oras/root/repo/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package repo

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -74,12 +75,24 @@ func listRepository(ctx context.Context, opts repositoryOptions) error {
if err != nil {
return err
}
return reg.Repositories(ctx, opts.last, func(repos []string) error {
err = reg.Repositories(ctx, opts.last, func(repos []string) error {
for _, repo := range repos {
if subRepo, found := strings.CutPrefix(repo, opts.namespace); found {
fmt.Println(subRepo)
}
}
return nil
})

if err != nil {
var repoErr error
if opts.namespace != "" {
repoErr = fmt.Errorf("could not list repositories for %q with prefix %q", reg.Reference.Host(), opts.namespace)
} else {
repoErr = fmt.Errorf("could not list repositories for %q", reg.Reference.Host())
}
return errors.Join(repoErr, err)
}

return nil
}

0 comments on commit dbf40e4

Please sign in to comment.