From d831f06b83f350142b80663896ce1e1fd6f9270c Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 21 Mar 2024 01:20:34 +0000 Subject: [PATCH] resolved comments Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/remote.go | 8 ++++---- cmd/oras/root/blob/push.go | 2 +- cmd/oras/root/manifest/push.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/oras/internal/option/remote.go b/cmd/oras/internal/option/remote.go index e7081672b..9341657cf 100644 --- a/cmd/oras/internal/option/remote.go +++ b/cmd/oras/internal/option/remote.go @@ -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 { diff --git a/cmd/oras/root/blob/push.go b/cmd/oras/root/blob/push.go index fb688870c..301e8e709 100644 --- a/cmd/oras/root/blob/push.go +++ b/cmd/oras/root/blob/push.go @@ -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 { diff --git a/cmd/oras/root/manifest/push.go b/cmd/oras/root/manifest/push.go index fc72a4524..28108d29e 100644 --- a/cmd/oras/root/manifest/push.go +++ b/cmd/oras/root/manifest/push.go @@ -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 } }