Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah committed Jan 20, 2023
1 parent 18ebd6c commit 37b1e22
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +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) {
func applyPrefix(prefix, description string) (flagPrefix, notePrefix string) {
if prefix == "" {
return "", ""
}
return prefix + "-", description + " "
}

Expand All @@ -79,9 +82,9 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description
)
if prefix == "" {
shortUser, shortPassword = "u", "p"
} else {
flagPrefix, notePrefix = generatePrefix(prefix, description)
}
flagPrefix, notePrefix = applyPrefix(prefix, description)

if opts.applyDistributionSpec {
opts.distributionSpec.ApplyFlagsWithPrefix(fs, prefix, description)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/internal/option/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +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) {
flagPrefix, notePrefix := generatePrefix(prefix, description)
flagPrefix, notePrefix := applyPrefix(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")
}
2 changes: 1 addition & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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) {
flagPrefix, notePrefix := generatePrefix(prefix, description)
flagPrefix, notePrefix := applyPrefix(prefix, description)
fs.BoolVarP(&opts.isOCILayout, flagPrefix+"oci-layout", "", false, "Set "+notePrefix+"target as an OCI image layout.")
}

Expand Down

0 comments on commit 37b1e22

Please sign in to comment.