feat: add --hide-pretty-plan and --show-plan to prepare (#284)

This commit is contained in:
Michael Bianco
2025-09-30 05:10:28 -06:00
committed by GitHub
parent 9c9a6d029c
commit 865def5e53
+25 -2
View File
@@ -26,6 +26,14 @@ var PrepareCommand = &cli.Command{
Name: "info-out",
Usage: "output file for the JSON serialized build result info",
},
&cli.BoolFlag{
Name: "show-plan",
Usage: "dump the build plan to stdout",
},
&cli.BoolFlag{
Name: "hide-pretty-plan",
Usage: "hide the pretty-printed build result output",
},
}, commonPlanFlags()...),
Action: func(ctx context.Context, cmd *cli.Command) error {
buildResult, _, _, err := GenerateBuildResultForCommand(cmd)
@@ -33,14 +41,29 @@ var PrepareCommand = &cli.Command{
return cli.Exit(err, 1)
}
// Pretty print the result to stdout
core.PrettyPrintBuildResult(buildResult, core.PrintOptions{Version: Version})
// Pretty print the result to stdout unless hidden
if !cmd.Bool("hide-pretty-plan") {
core.PrettyPrintBuildResult(buildResult, core.PrintOptions{Version: Version})
}
if !buildResult.Success {
os.Exit(1)
return nil
}
// Show plan to stdout if requested
if cmd.Bool("show-plan") {
planMap, err := addSchemaToPlanMap(buildResult.Plan)
if err != nil {
return cli.Exit(err, 1)
}
serialized, err := json.MarshalIndent(planMap, "", " ")
if err != nil {
return cli.Exit(err, 1)
}
os.Stdout.Write(serialized)
}
// Save plan if requested
if planOut := cmd.String("plan-out"); planOut != "" {
// Include $schema in the plan JSON for editor support