index

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

cmd/library/index/index.go

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipDocument = errors.New("skip document")

ErrSkipDocument is returned when a document should be skipped during indexing.

View Source
var IndexCmd = &cobra.Command{
	Use:     "index --thea-path <path> --template-path <path> [-o <output-file>]",
	Example: `  contextvibes library index --thea-path ../THEA/docs -o manifest.json`,
	Args:    cobra.NoArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr())
		logger := globals.AppLogger

		var allMetadata []DocumentMetadata
		processedFiles := make(map[string]bool)

		if indexPathTHEA != "" {
			theaMetadata, err := processDirectory(indexPathTHEA, "THEA", processedFiles, logger)
			if err != nil {
				presenter.Error("Error processing THEA directory: %v", err)
			}
			allMetadata = append(allMetadata, theaMetadata...)
		}

		if indexPathTemplate != "" {
			templateMetadata, err := processDirectory(
				indexPathTemplate,
				"Template",
				processedFiles,
				logger,
			)
			if err != nil {
				presenter.Error("Error processing Template directory: %v", err)
			}
			allMetadata = append(allMetadata, templateMetadata...)
		}

		jsonData, err := json.MarshalIndent(allMetadata, "", "  ")
		if err != nil {
			return fmt.Errorf("failed to marshal metadata to JSON: %w", err)
		}

		if err := os.WriteFile(indexPathOut, jsonData, 0o600); err != nil {
			return fmt.Errorf("failed to write index file to %s: %w", indexPathOut, err)
		}

		presenter.Success("Successfully created document manifest at: %s", indexPathOut)
		return nil
	},
}

IndexCmd represents the index command

Functions

This section is empty.

Types

type DocumentMetadata

type DocumentMetadata struct {
	ID                string   `json:"id"`
	FileExtension     string   `json:"fileExtension"`
	Title             string   `json:"title"`
	ArtifactVersion   string   `json:"artifactVersion,omitempty"`
	Summary           string   `json:"summary,omitempty"`
	UsageGuidance     []string `json:"usageGuidance,omitempty"`
	Owner             string   `json:"owner,omitempty"`
	CreatedDate       string   `json:"createdDate,omitempty"`
	LastModifiedDate  string   `json:"lastModifiedDate,omitempty"`
	DefaultTargetPath string   `json:"defaultTargetPath,omitempty"`
	Tags              []string `json:"tags,omitempty"`
	SourceFilePath    string   `json:"sourceFilePath"`
}

Jump to

Keyboard shortcuts

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