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: add copyCmd() #432

Merged
merged 18 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 7 additions & 20 deletions cmd/oras/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ type copyOptions struct {

func copyCmd() *cobra.Command {
var opts copyOptions
opts.src.SetMark("from-")
opts.dst.SetMark("to-")

opts.src.SetPrefix("source")
opts.dst.SetPrefix("destination")
opts.src.SetBlockPassStdin()
opts.dst.SetBlockPassStdin()

cmd := &cobra.Command{
Use: "copy <from-ref> <to-ref>",
Aliases: []string{"cp"},
Short: "Copy a manifest between repositories",
Long: `Copy artifacts from one reference to another reference
Short: "Copy manifests between repositories",
Long: `Copy manifests between repositories

Examples - Copy the manifest tagged 'v1' from from repository 'localhost:5000/net-monitor' to repository 'localhost:5000/net-monitor-copy'
Examples - Copy the manifest tagged 'v1' from repository 'localhost:5000/net-monitor' to repository 'localhost:5000/net-monitor-copy'
oras cp localhost:5000/net-monitor:v1 localhost:5000/net-monitor-copy:v1
Examples - Copy the manifest tagged 'v1' and referrer artifacts from repository 'localhost:5000/net-monitor' to 'localhost:5000/net-monitor-copy'
oras cp -r localhost:5000/net-monitor:v1 localhost:5000/net-monitor-copy:v1
Expand Down Expand Up @@ -91,21 +90,9 @@ func runCopy(opts copyOptions) error {
}
var desc ocispec.Descriptor
if opts.rescursive {
desc, err = oras.ExtendedCopy(ctx,
src,
srcRef.ReferenceOrDefault(),
dst,
dstRef.ReferenceOrDefault(),
oras.DefaultExtendedCopyOptions,
)
desc, err = oras.ExtendedCopy(ctx, src, srcRef.ReferenceOrDefault(), dst, dstRef.ReferenceOrDefault(), oras.DefaultExtendedCopyOptions)
} else {
desc, err = oras.Copy(ctx,
src,
srcRef.ReferenceOrDefault(),
dst,
dstRef.ReferenceOrDefault(),
oras.DefaultCopyOptions,
)
desc, err = oras.Copy(ctx, src, srcRef.ReferenceOrDefault(), dst, dstRef.ReferenceOrDefault(), oras.DefaultCopyOptions)

Choose a reason for hiding this comment

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

Not a strong opinion, I'd like to create a struct wrapping up related params instead of passing too many params directly.

}
if err != nil {
return err
Expand Down
25 changes: 14 additions & 11 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,33 @@ type Remote struct {
Username string
PasswordFromStdin bool
Password string
// TODO

notePrefix string
flagPrefix string
blockPassStdin bool
}

// ApplyFlags applies flags to a command flag set.
func (opts *Remote) ApplyFlags(fs *pflag.FlagSet) {
fs.StringArrayVarP(&opts.Configs, opts.flagPrefix+"config", "c", nil, "auth config path")
fs.StringVarP(&opts.Username, opts.flagPrefix+"username", "u", "", "registry username")
fs.StringVarP(&opts.Password, opts.flagPrefix+"password", "p", "", "registry password or identity token")
fs.StringVarP(&opts.Username, opts.flagPrefix+"username", "u", "", opts.notePrefix+"registry username")
fs.StringVarP(&opts.Password, opts.flagPrefix+"password", "p", "", opts.notePrefix+"registry password or identity token")
fs.BoolVarP(&opts.Insecure, opts.flagPrefix+"insecure", "", false, "allow connections to "+opts.notePrefix+"SSL registry without certs")
fs.BoolVarP(&opts.PlainHTTP, opts.flagPrefix+"plain-http", "", false, "allow insecure connections to "+opts.notePrefix+"registry without SSL")
fs.StringVarP(&opts.CACertFilePath, opts.flagPrefix+"ca-file", "", "", "server certificate authority file for the remote "+opts.notePrefix+"registry")

fs.StringArrayVarP(&opts.Configs, "config", "c", nil, "auth config path")
if !opts.blockPassStdin {
fs.BoolVarP(&opts.PasswordFromStdin, "password-stdin", "", false, "read password or identity token from stdin")
}
fs.BoolVarP(&opts.Insecure, opts.flagPrefix+"insecure", "", false, "allow connections to SSL registry without certs")
fs.StringVarP(&opts.CACertFilePath, opts.flagPrefix+"ca-file", "", "", "server certificate authority file for the remote registry")
fs.BoolVarP(&opts.PlainHTTP, opts.flagPrefix+"plain-http", "", false, "allow insecure connections to registry without SSL")
}

// SetMark set flagPrefix value.
func (opts *Remote) SetMark(hostname string) {
opts.flagPrefix = hostname
// SetPrefix sets prefix for applicable flags.
func (opts *Remote) SetPrefix(target string) {
opts.flagPrefix = target + "-"
opts.notePrefix = target + " "
}

// SetBlockPassStdin set blockPassStdin value.
// SetBlockPassStdin disables Password input from Stdin.
func (opts *Remote) SetBlockPassStdin() {
junczhu marked this conversation as resolved.
Show resolved Hide resolved
opts.blockPassStdin = true
}
Expand Down