From d70063e887f5d58f7dbcc8d88944e547880ecff2 Mon Sep 17 00:00:00 2001 From: CamrynCarter Date: Thu, 13 Aug 2026 15:09:29 -0700 Subject: [PATCH] default output to stdout --- cmd/hauler/cli/store.go | 6 +++--- cmd/hauler/cli/store/create_manifest.go | 28 ++++++++++++++++--------- internal/flags/create.go | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/hauler/cli/store.go b/cmd/hauler/cli/store.go index 53e7f6f..e9f8889 100644 --- a/cmd/hauler/cli/store.go +++ b/cmd/hauler/cli/store.go @@ -517,13 +517,13 @@ func addStoreCreateManifest(rso *flags.StoreRootOpts, ro *flags.CliRootOpts) *co cmd := &cobra.Command{ Use: "manifest", Short: "Create a hauler content manifest from the store's metadata", - Example: ` # generate a manifest for the default store into ./store-manifest.yaml + Example: ` # print a manifest for the default store to stdout hauler store create manifest - # generate a manifest for a specific store into ./my-store-manifest.yaml + # print a manifest for a specific store to stdout hauler store create manifest --store /path/to/my-store - # generate a manifest for a specific store into a custom path + # write a manifest for a specific store to a file hauler store create manifest --store /path/to/store --output my-manifest.yaml`, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/hauler/cli/store/create_manifest.go b/cmd/hauler/cli/store/create_manifest.go index 0905ad8..f791465 100644 --- a/cmd/hauler/cli/store/create_manifest.go +++ b/cmd/hauler/cli/store/create_manifest.go @@ -55,10 +55,16 @@ type manifestDoc struct { // CreateManifestCmd walks the store's OCI index (and the manifests/configs it // references) to reconstruct a hauler content manifest capable of recreating the // store's contents via `hauler store sync`. It groups discovered content into -// Images/Charts/Files documents and writes them to o.Output. +// Images/Charts/Files documents and writes them to o.Output, or to stdout when +// o.Output is empty. func CreateManifestCmd(ctx context.Context, o *flags.CreateManifestOpts, s *store.Layout) error { l := log.FromContext(ctx) + toStdout := o.Output == "" + if toStdout { + l.SetLevel("fatal") + } + var images []manifestImage var charts []manifestChart var files []manifestFile @@ -184,11 +190,6 @@ func CreateManifestCmd(ctx context.Context, o *flags.CreateManifestOpts, s *stor base := filepath.Base(s.Root) - output := o.Output - if output == "" { - output = base + "-manifest.yaml" - } - var out strings.Builder if len(images) > 0 { if err := writeDoc(&out, "", consts.ImagesContentKind, base+"-images", struct { @@ -216,12 +217,19 @@ func CreateManifestCmd(ctx context.Context, o *flags.CreateManifestOpts, s *stor } } - if err := os.WriteFile(output, []byte(out.String()), 0o644); err != nil { - return fmt.Errorf("writing manifest to [%s]: %w", output, err) + if toStdout { + if _, err := os.Stdout.Write([]byte(out.String())); err != nil { + return err + } + return nil } - outPath := output - if abs, err := filepath.Abs(output); err == nil { + if err := os.WriteFile(o.Output, []byte(out.String()), 0o644); err != nil { + return fmt.Errorf("writing manifest to [%s]: %w", o.Output, err) + } + + outPath := o.Output + if abs, err := filepath.Abs(o.Output); err == nil { outPath = abs } l.Infof("wrote manifest with [%d] image(s), [%d] chart(s), [%d] file(s) to [%s]", len(images), len(charts), len(files), outPath) diff --git a/internal/flags/create.go b/internal/flags/create.go index f97e5f8..b0d7ad2 100644 --- a/internal/flags/create.go +++ b/internal/flags/create.go @@ -11,5 +11,5 @@ type CreateManifestOpts struct { func (o *CreateManifestOpts) AddFlags(cmd *cobra.Command) { f := cmd.Flags() - f.StringVarP(&o.Output, "output", "o", "", "(Optional) Path to write the generated manifest to (default \"$STORENAME-manifest.yaml\")") + f.StringVarP(&o.Output, "output", "o", "", "(Optional) Path to write the generated manifest to (defaults to stdout)") }