Skip to content

Commit

Permalink
adding on jam summarize for extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas committed Jun 26, 2024
1 parent a1c6c20 commit 03a19be
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions commands/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type summarizeFlags struct {
buildpackTarballPath string
extensionTarballPath string
format string
}

Expand All @@ -19,16 +20,21 @@ func summarize() *cobra.Command {
Use: "summarize",
Short: "summarize buildpackage",
RunE: func(cmd *cobra.Command, args []string) error {
return summarizeRun(*flags)
isBuildpack, _ := cmd.Flags().GetString("buildpack")
if isBuildpack != "" {
return summarizeRun(*flags)
} else {
return summarizeExtensionRun(*flags)
}
},
}
cmd.Flags().StringVar(&flags.buildpackTarballPath, "buildpack", "", "path to a buildpackage tarball (required)")
cmd.Flags().StringVar(&flags.format, "format", "markdown", "format of output options are (markdown, json)")
cmd.Flags().StringVar(&flags.extensionTarballPath, "extension", "", "path to a buildpackage tarball (required)")
cmd.PersistentFlags().StringVar(&flags.format, "format", "markdown", "format of output options are (markdown, json)")

cmd.MarkFlagsOneRequired("buildpack", "extension")
cmd.MarkFlagsMutuallyExclusive("buildpack", "extension")

err := cmd.MarkFlagRequired("buildpack")
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to mark buildpack flag as required")
}
return cmd
}

Expand All @@ -55,3 +61,24 @@ func summarizeRun(flags summarizeFlags) error {

return nil
}

func summarizeExtensionRun(flags summarizeFlags) error {

extensionInspector := internal.NewExtensionInspector()
formatter := internal.NewExtensionFormatter(os.Stdout)
configs, err := extensionInspector.Dependencies(flags.extensionTarballPath)
if err != nil {
return fmt.Errorf("failed to inspect extension dependencies: %w", err)
}

switch flags.format {
case "markdown":
formatter.Markdown(configs)
case "json":
formatter.JSON(configs)
default:
return fmt.Errorf("unknown format %q, please choose from the following formats: markdown, json)", flags.format)
}

return nil
}

0 comments on commit 03a19be

Please # to comment.