From 1a64e7599a3269bb1e55d83c8b8e70d5b1a5c8ea Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Sat, 8 Jun 2024 09:08:32 -0600 Subject: [PATCH] chore: add text type as default format Signed-off-by: Terry Howe --- cmd/oras/internal/option/format.go | 6 +++--- cmd/oras/root/attach.go | 2 +- cmd/oras/root/discover.go | 1 + cmd/oras/root/manifest/fetch.go | 3 ++- cmd/oras/root/pull.go | 2 +- cmd/oras/root/push.go | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/oras/internal/option/format.go b/cmd/oras/internal/option/format.go index a5103be30..1372b2d0d 100644 --- a/cmd/oras/internal/option/format.go +++ b/cmd/oras/internal/option/format.go @@ -65,7 +65,7 @@ var ( Usage: "Get referrers recursively and print in tree format", } FormatTypeText = &FormatType{ - Name: "", + Name: "text", Usage: "Print in text format", } ) @@ -87,7 +87,7 @@ func (opts *Format) ApplyFlags(fs *pflag.FlagSet) { } _ = w.Flush() // apply flags - fs.StringVar(&opts.FormatFlag, "format", opts.FormatFlag, buf.String()) + fs.StringVar(&opts.FormatFlag, "format", FormatTypeText.Name, buf.String()) fs.StringVar(&opts.Template, "template", "", "[Experimental] Template string used to format output") } @@ -97,7 +97,7 @@ func (opts *Format) Parse(_ *cobra.Command) error { return err } - if opts.Type == "" { + if opts.Type == FormatTypeText.Name { // flag not specified return nil } diff --git a/cmd/oras/root/attach.go b/cmd/oras/root/attach.go index ddc77aeba..1c226ca68 100644 --- a/cmd/oras/root/attach.go +++ b/cmd/oras/root/attach.go @@ -102,7 +102,7 @@ Example - Attach file to the manifest tagged 'v1' in an OCI image layout folder opts.FlagDescription = "[Preview] attach to an arch-specific subject" _ = cmd.MarkFlagRequired("artifact-type") opts.EnableDistributionSpecFlag() - opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate} + opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate, option.FormatTypeText} option.ApplyFlags(&opts, cmd.Flags()) return oerrors.Command(cmd, &opts.Target) } diff --git a/cmd/oras/root/discover.go b/cmd/oras/root/discover.go index 5cde8cfa4..c86a51f73 100644 --- a/cmd/oras/root/discover.go +++ b/cmd/oras/root/discover.go @@ -105,6 +105,7 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI image layout option.FormatTypeTable, option.FormatTypeJSON.WithUsage("Get direct referrers and output in JSON format"), option.FormatTypeGoTemplate.WithUsage("Print direct referrers using the given Go template"), + option.FormatTypeText, } opts.EnableDistributionSpecFlag() option.ApplyFlags(&opts, cmd.Flags()) diff --git a/cmd/oras/root/manifest/fetch.go b/cmd/oras/root/manifest/fetch.go index c38afe413..0e830a3f6 100644 --- a/cmd/oras/root/manifest/fetch.go +++ b/cmd/oras/root/manifest/fetch.go @@ -73,7 +73,7 @@ Example - Fetch raw manifest from an OCI layout archive file 'layout.tar': Args: oerrors.CheckArgs(argument.Exactly(1), "the manifest to fetch"), PreRunE: func(cmd *cobra.Command, args []string) error { switch { - case opts.outputPath == "-" && opts.FormatFlag != "": + case opts.outputPath == "-" && opts.FormatFlag != option.FormatTypeText.Name: return fmt.Errorf("`--output -` cannot be used with `--format %s` at the same time", opts.Template) case opts.outputPath == "-" && opts.OutputDescriptor: return fmt.Errorf("`--descriptor` cannot be used with `--output -` at the same time") @@ -101,6 +101,7 @@ Example - Fetch raw manifest from an OCI layout archive file 'layout.tar': opts.AllowedTypes = []*option.FormatType{ option.FormatTypeJSON.WithUsage("Print in prettified JSON format"), option.FormatTypeGoTemplate.WithUsage("Print using the given Go template"), + option.FormatTypeText, } option.ApplyFlags(&opts, cmd.Flags()) return oerrors.Command(cmd, &opts.Target) diff --git a/cmd/oras/root/pull.go b/cmd/oras/root/pull.go index 061cd1b79..af5abca34 100644 --- a/cmd/oras/root/pull.go +++ b/cmd/oras/root/pull.go @@ -104,7 +104,7 @@ Example - Pull artifact files from an OCI layout archive 'layout.tar': cmd.Flags().StringVarP(&opts.Output, "output", "o", ".", "output directory") cmd.Flags().StringVarP(&opts.ManifestConfigRef, "config", "", "", "output manifest config file") cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 3, "concurrency level") - opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate} + opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate, option.FormatTypeText} option.ApplyFlags(&opts, cmd.Flags()) return oerrors.Command(cmd, &opts.Target) } diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index ad6145373..0d40f5a39 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -144,7 +144,7 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t cmd.Flags().StringVarP(&opts.manifestConfigRef, "config", "", "", "`path` of image config file") cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type") cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 5, "concurrency level") - opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate} + opts.AllowedTypes = []*option.FormatType{option.FormatTypeJSON, option.FormatTypeGoTemplate, option.FormatTypeText} option.ApplyFlags(&opts, cmd.Flags()) return oerrors.Command(cmd, &opts.Target) }