show

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShowCmd = &cobra.Command{
	Use:   "show <REQ-ID>",
	Short: "Display all CANARY tokens for a requirement",
	Long: `Show displays all CANARY tokens for a specific requirement ID.

Displays:
- Feature name, aspect, status
- File location and line number
- Test and benchmark references
- Owner and priority

Resolution:
- An exact requirement ID is shown directly.
- A prefix that uniquely identifies one requirement is resolved to it.
- A prefix that matches several requirements is reported as ambiguous, with
  the sorted candidate list, and exits non-zero.
- When there is no index (no .canary/canary.db), show falls back to a live
  filesystem scan of the working directory and marks the output accordingly.

Grouping:
- By default, groups by aspect (CLI, API, Engine, etc.)
- Use --group-by status to group by implementation status
- Use --json for machine-readable output

Examples:
  canary show CBIN-133
  canary show CBIN-133 --group-by status
  canary show CBIN-133 --json`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		prompt, _ := cmd.Flags().GetString("prompt")
		var promptContent string
		if prompt != "" {
			c, err := utils.LoadPrompt(prompt)
			if err != nil {
				return err
			}
			promptContent = c
		}
		reqID := args[0]
		groupBy, _ := cmd.Flags().GetString("group-by")
		jsonOutput, _ := cmd.Flags().GetBool("json")
		if noColor, _ := cmd.Flags().GetBool("no-color"); noColor {
			color.NoColor = true
		}

		dbPath, _ := cmd.Flags().GetString("db")
		projectID := utils.ReadProjectID(cmd)

		tokens, source, err := loadTokens(cmd, dbPath, projectID, reqID)
		if err != nil {
			return err
		}

		if len(tokens) == 0 {

			if jsonOutput {
				fmt.Fprintf(os.Stderr, "No tokens found for %s\n", reqID)
				fmt.Fprintln(os.Stderr, "\nSuggestions:")
				fmt.Fprintln(os.Stderr, "  • Run: canary list")
				fmt.Fprintln(os.Stderr, "  • Check requirement ID format (e.g., CBIN-XXX)")
				if jerr := outputTokensJSON([]*storage.Token{}); jerr != nil {
					return jerr
				}
				return fmt.Errorf("requirement not found")
			}

			fmt.Printf("No tokens found for %s\n", reqID)
			fmt.Println("\nSuggestions:")
			fmt.Println("  • Run: canary list")
			fmt.Println("  • Check requirement ID format (e.g., CBIN-XXX)")
			return fmt.Errorf("requirement not found")
		}

		if jsonOutput {
			return outputTokensJSON(tokens)
		}

		if promptContent != "" {
			fmt.Println(promptContent)
			fmt.Println()
		}
		fmt.Printf("Tokens for %s (source: %s):\n\n", tokens[0].ReqID, source)
		output := canary.FormatTokensTable(tokens, groupBy)
		fmt.Println(output)

		return nil
	},
}

CANARY: REQ=CBIN-CLI-001; FEATURE="ShowCmd"; ASPECT=CLI; STATUS=TESTED; TEST=TestCANARY_CBIN_CLI_001_CLI_ShowCmd; UPDATED=2026-08-30

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL