mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-08-19 20:36:30 +00:00
default output to stdout
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user