Documentation
¶
Overview ¶
Package discovery provides version source detection and discovery services for the sley CLI. It scans for .version files and manifest files (package.json, Cargo.toml, etc.) to help users understand their project structure and suggest appropriate configurations.
Index ¶
- func GetUniqueVersions(result *Result) []string
- func IsVersionConsistent(result *Result) bool
- type DetectionMode
- type FileFilter
- type KnownManifest
- type ManifestSource
- type Mismatch
- type Module
- type Result
- type Service
- func (s *Service) Discover(ctx context.Context, root string) (*Result, error)
- func (s *Service) DiscoverManifestsOnly(ctx context.Context, root string) ([]ManifestSource, error)
- func (s *Service) DiscoverModulesOnly(ctx context.Context, root string) ([]Module, error)
- func (s *Service) DiscoverWithDepth(ctx context.Context, root string, manifestMaxDepth int) (*Result, error)
- type SyncCandidate
- type VersionSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUniqueVersions ¶
GetUniqueVersions returns a list of unique versions found in the discovery result.
func IsVersionConsistent ¶
IsVersionConsistent returns true if all discovered sources have the same version.
Types ¶
type DetectionMode ¶
type DetectionMode int
DetectionMode indicates the type of project structure detected.
const ( // NoModules indicates no .version files were found. NoModules DetectionMode = iota // SingleModule indicates a single .version file was found. SingleModule // MultiModule indicates multiple .version files were found. MultiModule )
func (DetectionMode) String ¶
func (m DetectionMode) String() string
String returns a human-readable representation of the detection mode.
type FileFilter ¶
FileFilter is a function type for filtering discovered files.
type KnownManifest ¶
type KnownManifest struct {
// Filename is the expected filename.
Filename string
// Format is the file format.
Format parser.Format
// Field is the dot-notation path to the version field.
Field string
// Description is a human-readable description.
Description string
// Priority determines discovery order (lower = higher priority).
Priority int
}
KnownManifest describes a known manifest file type for discovery.
func DefaultKnownManifests ¶
func DefaultKnownManifests() []KnownManifest
DefaultKnownManifests returns the list of known manifest files to discover.
type ManifestSource ¶
type ManifestSource struct {
// Path is the absolute path to the manifest file.
Path string
// RelPath is the relative path from the discovery root.
RelPath string
// Filename is the base name of the file (e.g., "package.json").
Filename string
// Version is the extracted version string.
Version string
// Format is the file format (json, yaml, toml, etc.).
Format parser.Format
// Field is the dot-notation path to the version field.
Field string
// Description is a human-readable description of the file type.
Description string
}
ManifestSource represents a discovered manifest file with version information.
type Mismatch ¶
type Mismatch struct {
// Source is the path of the file with the mismatched version.
Source string
// ExpectedVersion is what the version should be.
ExpectedVersion string
// ActualVersion is the version found in the file.
ActualVersion string
}
Mismatch represents a version mismatch between sources.
func DetectMismatches ¶
DetectMismatches analyzes discovery results and identifies version inconsistencies. It uses the primary version as the expected version and flags any sources that differ.
func DetectMismatchesWithCustomBase ¶
DetectMismatchesWithCustomBase checks for mismatches using a specified base version.
type Module ¶
type Module struct {
// Name is the module name (typically the directory name).
Name string
// Path is the absolute path to the .version file.
Path string
// RelPath is the relative path from the discovery root.
RelPath string
// Version is the current version string.
Version string
// Dir is the directory containing the .version file.
Dir string
}
Module represents a discovered .version file.
type Result ¶
type Result struct {
// Mode indicates the detected project mode.
Mode DetectionMode
// Modules contains discovered .version files (monorepo modules).
Modules []Module
// Manifests contains discovered manifest files with version information.
Manifests []ManifestSource
// SyncCandidates contains files suitable for dependency-check sync.
SyncCandidates []SyncCandidate
// Mismatches contains detected version mismatches.
Mismatches []Mismatch
}
Result represents the complete discovery result for a project.
func DiscoverAt ¶
func DiscoverAt(ctx context.Context, fsys core.FileSystem, cfg *config.Config, root string) (*Result, error)
DiscoverAt is a convenience function that creates a Service and runs discovery.
func (*Result) HasManifests ¶
HasManifests returns true if any manifest files were found.
func (*Result) HasMismatches ¶
HasMismatches returns true if version mismatches were detected.
func (*Result) HasModules ¶
HasModules returns true if any .version files were found.
func (*Result) PrimaryVersion ¶
PrimaryVersion returns the recommended primary version based on discovery. Priority: .version in cwd > first module > first manifest
func (*Result) WithFilter ¶
func (r *Result) WithFilter(filter FileFilter) []Module
WithFilter returns a filtered list of modules.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides version source discovery functionality.
func NewService ¶
func NewService(fs core.FileSystem, cfg *config.Config) *Service
NewService creates a new discovery Service.
func (*Service) DiscoverManifestsOnly ¶
DiscoverManifestsOnly is a convenience method that only discovers manifest files. It uses the configured manifest max depth (default: 3).
func (*Service) DiscoverModulesOnly ¶
DiscoverModulesOnly is a convenience method that only discovers .version files.
func (*Service) DiscoverWithDepth ¶
func (s *Service) DiscoverWithDepth(ctx context.Context, root string, manifestMaxDepth int) (*Result, error)
DiscoverWithDepth scans the given root directory with a specified manifest discovery depth. If manifestMaxDepth is -1, the configured default (or 3) is used.
type SyncCandidate ¶
type SyncCandidate struct {
// Path is the relative path to the file.
Path string
// Format is the file format.
Format parser.Format
// Field is the dot-notation path to the version field.
Field string
// Pattern is the regex pattern (for regex format).
Pattern string
// Version is the current version in the file.
Version string
// Description is a human-readable description.
Description string
}
SyncCandidate represents a file that can be synced via dependency-check.
func (SyncCandidate) ToFileConfig ¶
func (s SyncCandidate) ToFileConfig() parser.FileConfig
ToFileConfig converts a SyncCandidate to a parser.FileConfig.
type VersionSummary ¶
type VersionSummary struct {
// Version is the version string.
Version string
// Count is how many sources have this version.
Count int
// Sources lists the paths with this version.
Sources []string
}
VersionSummary provides a summary of version distribution.
func GetVersionSummary ¶
func GetVersionSummary(result *Result) []VersionSummary
GetVersionSummary returns a summary of version distribution across sources.