(ctx context.Context, cfg *sbom.Config)
| 114 | } |
| 115 | |
| 116 | func (cmd *SBOMGenerateCommand) RunContext(ctx context.Context, cfg *sbom.Config) int { |
| 117 | fmt.Fprintf(os.Stderr, "Generating %s SBOM for %s...\n", cfg.Format, cfg.ScanPath) |
| 118 | |
| 119 | // Create generator |
| 120 | generator := sbom.NewGenerator(*cfg) |
| 121 | |
| 122 | // Generate SBOM |
| 123 | sbomData, err := generator.Generate(ctx) |
| 124 | if err != nil { |
| 125 | cmd.Ui.Error(fmt.Sprintf("SBOM generation failed: %s", err)) |
| 126 | return 1 |
| 127 | } |
| 128 | |
| 129 | // Write to stdout (will be redirected to file via > operator) |
| 130 | _, err = os.Stdout.Write(sbomData) |
| 131 | if err != nil { |
| 132 | cmd.Ui.Error(fmt.Sprintf("Failed to write SBOM: %s", err)) |
| 133 | return 1 |
| 134 | } |
| 135 | |
| 136 | fmt.Fprintln(os.Stderr, "✓ SBOM generation completed") |
| 137 | |
| 138 | return 0 |
| 139 | |
| 140 | } |
| 141 | func (c *SBOMGenerateCommand) Synopsis() string { |
| 142 | return "Generate SBOM for the local system (internal use)" |
| 143 | } |
no test coverage detected