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: support specifying distribution spec in discover, cp and manifest push commands #757

Merged
merged 10 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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: 1 addition & 1 deletion cmd/oras/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Example - Copy an artifact and its referrers:
oras cp -r localhost:5000/net-monitor:v1 localhost:6000/net-monitor-copy:v1

Example - Copy an artifact and referrers using specific methods for the Referrers API:
oras cp -r --from-distribution-spec v1.1-referrers-api --to-distribution-spec v1.1-referrers-tag\
oras cp -r --from-distribution-spec v1.1-referrers-api --to-distribution-spec v1.1-referrers-tag \
localhost:5000/net-monitor:v1 localhost:6000/net-monitor-copy:v1

Example - Copy certain platform of an artifact:
Expand Down
7 changes: 5 additions & 2 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (opts *Remote) ApplyFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&opts.PasswordFromStdin, "password-stdin", "", false, "read password or identity token from stdin")
}

func generatePrefix(prefix, description string) (flagPrefix, notePrefix string) {
return prefix + "-", description + " "
}
Copy link
Contributor

@shizhMSFT shizhMSFT Jan 20, 2023

Choose a reason for hiding this comment

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

Suggested change
func generatePrefix(prefix, description string) (flagPrefix, notePrefix string) {
return prefix + "-", description + " "
}
func applyPrefix(prefix, description string) (flagPrefix, notePrefix string) {
if prefix == "" {
return "", ""
}
return prefix + "-", description + " "
}


// ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string.
// Commonly used for non-unary remote targets.
func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) {
Expand All @@ -76,8 +80,7 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description
if prefix == "" {
shortUser, shortPassword = "u", "p"
} else {
flagPrefix = prefix + "-"
notePrefix = description + " "
flagPrefix, notePrefix = generatePrefix(prefix, description)
}
if opts.applyDistributionSpec {
opts.distributionSpec.ApplyFlagsWithPrefix(fs, prefix, description)
Expand Down
9 changes: 1 addition & 8 deletions cmd/oras/internal/option/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ func (opts *distributionSpec) Parse() error {

// ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string.
func (opts *distributionSpec) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) {
var (
flagPrefix string
notePrefix string
)
if prefix != "" {
flagPrefix = prefix + "-"
notePrefix = description + " "
}
flagPrefix, notePrefix := generatePrefix(prefix, description)
fs.StringVar(&opts.specFlag, flagPrefix+"distribution-spec", "", "set OCI distribution spec version and API option for "+notePrefix+"target. options: v1.1-referrers-api, v1.1-referrers-tag")
}
16 changes: 2 additions & 14 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ type Target struct {
isOCILayout bool
}

// EnableDistributionSpecFlag set distribution specification flag as applicable.
func (opts *Target) EnableDistributionSpecFlag() {
opts.applyDistributionSpec = true
}

// ApplyFlags applies flags to a command flag set for unary target
func (opts *Target) ApplyFlags(fs *pflag.FlagSet) {
opts.applyFlagsWithPrefix(fs, "", "")
Expand All @@ -73,15 +68,8 @@ func (opts *Target) AnnotatedReference() string {
// Since there is only one target type besides the default `registry` type,
// the full form is not implemented until a new type comes in.
func (opts *Target) applyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) {
var (
flagPrefix string
noteSuffix string
)
if prefix != "" {
flagPrefix = prefix + "-"
noteSuffix = description + " "
}
fs.BoolVarP(&opts.isOCILayout, flagPrefix+"oci-layout", "", false, "Set "+noteSuffix+"target as an OCI image layout.")
flagPrefix, notePrefix := generatePrefix(prefix, description)
fs.BoolVarP(&opts.isOCILayout, flagPrefix+"oci-layout", "", false, "Set "+notePrefix+"target as an OCI image layout.")
}

// ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string.
Expand Down