Documentation
¶
Overview ¶
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information. Package version provides version resolution functionality for commands.
Version Resolution ¶
The version resolver supports multiple formats for specifying versions:
1. "latest" - Resolves to the highest semantic version tag
2. Semantic version constraints:
- Caret ranges: ^1.2.3 (compatible with 1.2.3)
- Tilde ranges: ~1.2.3 (approximately 1.2.3)
- Comparisons: >1.0.0, >=1.0.0, <2.0.0, <=2.0.0
- Exact: =1.0.0
- Ranges: 1.0.0 - 2.0.0
- Wildcards: 1.x, 1.2.*
3. Exact tag names (with or without 'v' prefix):
- v1.2.3
- 1.2.3
4. Branch names:
- main
- develop
- feature/new-feature
5. Commit hashes:
- Full: abc123def456...
- Short: abc123d
Precedence ¶
When resolving versions, the resolver follows this precedence: 1. "latest" keyword resolution 2. Semantic version constraint matching 3. Exact tag matching (with v-prefix flexibility) 4. Pass-through for branches/commits
Semantic Version Handling ¶
The resolver handles semantic version tags with or without the 'v' prefix. When matching exact versions, it will try both formats automatically.
Example usage:
resolver := version.NewResolver(gitClient.GetTags)
resolved, err := resolver.ResolveVersion("/path/to/repo", "^1.0.0")
if err != nil {
log.Fatal(err)
}
// resolved might be "v1.5.2" - the highest version matching ^1.0.0
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information. Package version integration example
Copyright (c) 2025 Guilherme Silva Sousa Licensed under the MIT License See LICENSE file in the project root for full license information. Package version provides version resolution functionality for commands.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntegrationExample ¶
func IntegrationExample()
IntegrationExample shows how to integrate the version resolver with the rest of ccmd.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver handles version resolution for commands.
func NewResolver ¶
NewResolver creates a new version resolver.
func (*Resolver) ResolveVersion ¶
ResolveVersion resolves a version specification to a concrete Git reference. It handles the following formats: - "latest" - resolves to the latest semantic version tag - Semantic version constraint (e.g., "^1.0.0", "~2.1.0", ">=1.0.0") - Exact tag name (e.g., "v1.2.3" or "1.2.3") - Branch name (e.g., "main", "feature/xyz") - Commit hash (e.g., "abc123def")
Example ¶
package main
import (
"fmt"
"log"
"github.com/gifflet/ccmd/internal/git"
"github.com/gifflet/ccmd/pkg/version"
)
func main() {
// Create a git client
gitClient := git.NewClient("/tmp")
// Create a version resolver using the git client's GetTags method
resolver := version.NewResolver(gitClient.GetTags)
// Example 1: Resolve "latest" to the highest semantic version
resolved, err := resolver.ResolveVersion("/path/to/repo", "latest")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Latest version: %s\n", resolved)
// Example 2: Resolve a semantic version constraint
resolved, err = resolver.ResolveVersion("/path/to/repo", "^1.0.0")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Version matching ^1.0.0: %s\n", resolved)
// Example 3: Resolve an exact tag
resolved, err = resolver.ResolveVersion("/path/to/repo", "v1.2.3")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Exact tag: %s\n", resolved)
// Example 4: Pass through a branch name
resolved, err = resolver.ResolveVersion("/path/to/repo", "main")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Branch: %s\n", resolved)
}
Output:
func (*Resolver) ValidateReference ¶
ValidateReference checks if a Git reference exists in the repository. This is useful for validating branches and commit hashes.