Skip to content

Commit

Permalink
fix: support binary target in oras cp
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Feb 28, 2023
1 parent fc7a82b commit 6222ee9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (opts *Remote) ApplyFlags(fs *pflag.FlagSet) {
opts.ApplyFlagsWithPrefix(fs, "", "")
fs.BoolVarP(&opts.PasswordFromStdin, "password-stdin", "", false, "read password or identity token from stdin")
fs.StringArrayVarP(&opts.headerFlags, "header", "H", nil, "add custom headers to requests")
fs.StringArrayVarP(&opts.resolveFlag, "resolve", "", nil, "customized DNS formatted in `host:port:address[:address_port]`")
}

func applyPrefix(prefix, description string) (flagPrefix, notePrefix string) {
Expand Down Expand Up @@ -101,10 +102,6 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description
if fs.Lookup("registry-config") == nil {
fs.StringArrayVarP(&opts.Configs, "registry-config", "", nil, "`path` of the authentication file")
}

if fs.Lookup("resolve") == nil {
fs.StringArrayVarP(&opts.resolveFlag, "resolve", "", nil, "customized DNS formatted in `host:port:address[:address_port]`")
}
}

// Parse tries to read password with optional cmd prompt.
Expand Down
8 changes: 6 additions & 2 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ func (opts *Target) EnsureReferenceNotEmpty() error {
// BinaryTarget struct contains flags and arguments specifying two registries or
// image layouts.
type BinaryTarget struct {
From Target
To Target
From Target
To Target
resolveFlag []string
}

// EnableDistributionSpecFlag set distribution specification flag as applicable.
Expand All @@ -193,9 +194,12 @@ func (opts *BinaryTarget) EnableDistributionSpecFlag() {
func (opts *BinaryTarget) ApplyFlags(fs *pflag.FlagSet) {
opts.From.ApplyFlagsWithPrefix(fs, "from", "source")
opts.To.ApplyFlagsWithPrefix(fs, "to", "destination")
fs.StringArrayVarP(&opts.resolveFlag, "resolve", "", nil, "customized DNS formatted in `host:port:address[:address_port]`")
}

// Parse parses user-provided flags and arguments into option struct.
func (opts *BinaryTarget) Parse() error {
opts.From.resolveFlag = opts.resolveFlag
opts.To.resolveFlag = opts.resolveFlag
return Parse(opts)
}

0 comments on commit 6222ee9

Please sign in to comment.