Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Mar 21, 2024
1 parent fdd3218 commit d831f06
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description

// CheckStdinConflict checks if opts.PasswordFromStdin or opts.IdentityTokenFromStdin
// conflicts with read file from input.
func (opts *Remote) CheckStdinConflict() error {
func (opts *Remote) CheckStdinConflict(usage string) error {
if opts.PasswordFromStdin {
return fmt.Errorf("`-` read file from input and `--%s` read password from input cannot be both used", passwordFromStdinFlag)
return fmt.Errorf("%s and `--%s` read password from input cannot be both used", usage, passwordFromStdinFlag)
} else if opts.IdentityTokenFromStdin {
return fmt.Errorf("`-` read file from input and `--%s` read identity token from input cannot be both used", identityTokenFromStdinFlag)
return fmt.Errorf("%s and `--%s` read identity token from input cannot be both used", usage, identityTokenFromStdinFlag)
}
return nil
}

// Parse tries to read password with optional cmd prompt.
func (opts *Remote) Parse() error {
// if basic auth flags and id token flags are both used, return an error
// check that basic auth flags and identity token flags are not both used.
var flagChecker = func(values []bool, flags []string) string {
for i, v := range values {
if v {
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/blob/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Example - Push blob 'hi.txt' into an OCI image layout folder 'layout-dir':
opts.RawReference = args[0]
opts.fileRef = args[1]
if opts.fileRef == "-" {
if err := opts.CheckStdinConflict(); err != nil {
if err := opts.CheckStdinConflict("`-` read file from input"); err != nil {
return err
}
if opts.size < 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Example - Push a manifest to an OCI image layout folder 'layout-dir' and tag wit
PreRunE: func(cmd *cobra.Command, args []string) error {
opts.fileRef = args[1]
if opts.fileRef == "-" {
if err := opts.CheckStdinConflict(); err != nil {
if err := opts.CheckStdinConflict("`-` read file from input"); err != nil {
return err
}
}
Expand Down

0 comments on commit d831f06

Please sign in to comment.