files

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilesCmd = &cobra.Command{
	Use:   "files <REQ-ID>",
	Short: "List implementation files for a requirement",
	Long: `Files lists all implementation files containing tokens for a requirement.

By default, excludes spec and template files, showing only actual implementation.
Files are grouped by aspect and show token counts.

Examples:
  canary files CBIN-133
  canary files CBIN-133 --all  # Include spec/template files`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		prompt, _ := cmd.Flags().GetString("prompt")
		if prompt != "" {
			if _, err := utils.LoadPrompt(prompt); err != nil {
				return err
			}
		}
		reqID := args[0]
		includeAll, _ := cmd.Flags().GetBool("all")
		dbPath, _ := cmd.Flags().GetString("db")
		jsonOutput, _ := cmd.Flags().GetBool("json")

		db, err := storage.Open(dbPath)
		if err != nil {
			fmt.Fprintf(os.Stderr, "⚠️  Database not found\n")
			fmt.Fprintf(os.Stderr, "   Suggestion: Run 'canary index' to build database\n\n")
			return fmt.Errorf("open database: %w", err)
		}
		defer db.Close()

		excludeSpecs := !includeAll
		fileGroups, err := db.GetFilesByReqID(reqID, excludeSpecs)
		if err != nil {
			return fmt.Errorf("query files: %w", err)
		}

		if len(fileGroups) == 0 {
			fmt.Printf("No implementation files found for %s\n", reqID)
			if !includeAll {
				fmt.Println("\nTip: Use --all to include spec/template files")
			}
			return fmt.Errorf("no files found")
		}

		if jsonOutput {
			enc := json.NewEncoder(os.Stdout)
			return enc.Encode(buildFilesJSON(reqID, fileGroups))
		}

		fmt.Printf("Implementation files for %s:\n\n", reqID)
		fmt.Print(canary.FormatFilesList(fileGroups))

		return nil
	},
}

CANARY: REQ=CBIN-CLI-001; FEATURE="FilesCmd"; ASPECT=CLI; STATUS=TESTED; TEST=TestCANARY_CBIN_CLI_001_CLI_FilesCmd; UPDATED=2026-08-29

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