diff --git a/cmd/oras/internal/option/format.go b/cmd/oras/internal/option/format.go index fa7c9509c..2c0405a0d 100644 --- a/cmd/oras/internal/option/format.go +++ b/cmd/oras/internal/option/format.go @@ -32,13 +32,13 @@ const ( FormatTypeGoTemplate = "go-template" ) -// FormatType represents a custom type for formatting. +// FormatType represents a custom description in help doc. type FormatType struct { Name string Usage string } -// Format contains input and parsed options to format output. +// Format contains input and parsed options for formatted output flags. type Format struct { Type string Template string @@ -69,7 +69,7 @@ func (opts *Format) ApplyFlags(fs *pflag.FlagSet) { // apply flags fs.StringVar(&opts.Input, "format", opts.Input, usage) - fs.StringVar(&opts.Template, "template", "", `Template string used to format output`) + fs.StringVar(&opts.Template, "template", "", "Template string used to format output") } // Parse parses the input format flag. @@ -98,6 +98,7 @@ func (opts *Format) Parse(_ *cobra.Command) error { } func (opts *Format) parseFlag() error { + opts.Type = opts.Input if opts.Template != "" { // template explicitly set opts.Type = opts.Input @@ -112,8 +113,6 @@ func (opts *Format) parseFlag() error { // add parameter to template opts.Type = FormatTypeGoTemplate opts.Template = opts.Input[len(goTemplatePrefix):] - } else { - opts.Type = opts.Input } return nil } @@ -124,6 +123,7 @@ func (opts *Format) SetTypes(types []FormatType) { } // SetTypesAndDefault resets the format options and default value. +// Caller should make sure that this function is used before applying flags. func (opts *Format) SetTypesAndDefault(defaultType string, types []FormatType) { opts.Input = defaultType opts.types = types diff --git a/cmd/oras/root/discover.go b/cmd/oras/root/discover.go index 62640a521..f9abc7436 100644 --- a/cmd/oras/root/discover.go +++ b/cmd/oras/root/discover.go @@ -78,7 +78,6 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI image layout if err := oerrors.CheckMutuallyExclusiveFlags(cmd.Flags(), "format", "output"); err != nil { return err } - opts.RawReference = args[0] if err := option.Parse(cmd, &opts); err != nil { return err diff --git a/cmd/oras/root/pull.go b/cmd/oras/root/pull.go index 3f5e8cff2..db12f4bad 100644 --- a/cmd/oras/root/pull.go +++ b/cmd/oras/root/pull.go @@ -114,7 +114,6 @@ func runPull(cmd *cobra.Command, opts *pullOptions) error { if err != nil { return err } - // Copy Options copyOptions := oras.DefaultCopyOptions copyOptions.Concurrency = opts.concurrency diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index a06d184cf..5cc78053c 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -155,7 +155,6 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error { if err != nil { return err } - annotations, err := opts.LoadManifestAnnotations() if err != nil { return err