Skip to content
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

feat: command to list repositories in a remote registry #525

Merged
merged 18 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/oras/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"
"oras.land/oras/cmd/oras/manifest"
"oras.land/oras/cmd/oras/repository"
)

func main() {
Expand All @@ -22,6 +23,7 @@ func main() {
copyCmd(),
attachCmd(),
manifest.Cmd(),
repository.Cmd(),
)
if err := cmd.Execute(); err != nil {
os.Exit(1)
Expand Down
30 changes: 30 additions & 0 deletions cmd/oras/repository/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package repository

import (
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "repository [command]",
Short: "[Preview] Repository operations",
}

cmd.AddCommand(
listCmd(),
)
return cmd
}
76 changes: 76 additions & 0 deletions cmd/oras/repository/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package repository

import (
"fmt"

"github.com/spf13/cobra"
"oras.land/oras/cmd/oras/internal/option"
)

type repositoryOptions struct {
option.Remote
option.Common
hostname string
last string
}

func listCmd() *cobra.Command {
var opts repositoryOptions
cmd := &cobra.Command{
Use: "list REGISTRY [flags]",

Short: "[Preview] List the repositories under the registry",
Long: `[Preview] List the repositories under the registry

** This command is in preview and under development. **

Example - List the repositories under the registry:
oras repository list localhost:5000

Example - List the repositories under the registry that include values lexically after last:
oras repository list localhost:5000 --last "last_repo"
`,
Args: cobra.ExactArgs(1),
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
opts.hostname = args[0]
return listRepository(opts)
},
}

option.ApplyFlags(&opts, cmd.Flags())
cmd.Flags().StringVar(&opts.last, "last", "", "start after the repository specified by `last`")
return cmd
}

func listRepository(opts repositoryOptions) error {
ctx, _ := opts.SetLoggerLevel()
junczhu marked this conversation as resolved.
Show resolved Hide resolved
reg, err := opts.Remote.NewRegistry(opts.hostname, opts.Common)
if err != nil {
return err
}
if listErr := reg.Repositories(ctx, opts.last, func(repos []string) error {
for _, repo := range repos {
fmt.Println(repo)
}
return nil
}); listErr != nil {
return listErr
}
return nil
junczhu marked this conversation as resolved.
Show resolved Hide resolved
}