diff --git a/cmd/oras/internal/option/remote.go b/cmd/oras/internal/option/remote.go index cf918a430..4dde434d8 100644 --- a/cmd/oras/internal/option/remote.go +++ b/cmd/oras/internal/option/remote.go @@ -97,14 +97,11 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description fs.BoolVarP(&opts.Insecure, flagPrefix+"insecure", "", false, "allow connections to "+notePrefix+"SSL registry without certs") fs.BoolVarP(&opts.PlainHTTP, flagPrefix+"plain-http", "", false, "allow insecure connections to "+notePrefix+"registry without SSL check") fs.StringVarP(&opts.CACertFilePath, flagPrefix+"ca-file", "", "", "server certificate authority file for the remote "+notePrefix+"registry") + fs.StringArrayVarP(&opts.resolveFlag, flagPrefix+"resolve", "", nil, "customized DNS for "+notePrefix+"registry, formatted in `host:port:address[:address_port]`") 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. diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index bf0a4650a..fe4c066f9 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -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. @@ -193,9 +194,13 @@ 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, "base DNS rules formatted in `host:port:address[:address_port]` for --from-resolve and --to-resolve") } // Parse parses user-provided flags and arguments into option struct. func (opts *BinaryTarget) Parse() error { + // resolve are parsed in array order, latter will overwrite former + opts.From.resolveFlag = append(opts.resolveFlag, opts.From.resolveFlag...) + opts.To.resolveFlag = append(opts.resolveFlag, opts.To.resolveFlag...) return Parse(opts) }