Documentation
¶
Overview ¶
Package lock provides utilities for managing the commands.lock file that tracks installed commands, their versions, and installation details.
Index ¶
- Constants
- Variables
- type CommandSorter
- type Manager
- func (m *Manager) AddCommand(cmd *models.Command) error
- func (m *Manager) CountCommands() (int, error)
- func (m *Manager) ExportCommands() (map[string]*models.Command, error)
- func (m *Manager) GetCommand(name string) (*models.Command, error)
- func (m *Manager) GetCommandsBySource(source string) ([]*models.Command, error)
- func (m *Manager) HasCommand(name string) bool
- func (m *Manager) ImportCommands(commands map[string]*models.Command, overwrite bool) error
- func (m *Manager) ListCommands() ([]*models.Command, error)
- func (m *Manager) ListCommandsSorted(sortBy string) ([]*models.Command, error)
- func (m *Manager) Load() error
- func (m *Manager) RemoveCommand(name string) error
- func (m *Manager) Save() error
- func (m *Manager) SearchCommands(query string) ([]*models.Command, error)
- func (m *Manager) UpdateCommand(name string, updateFn func(*models.Command) error) error
Examples ¶
Constants ¶
const ( // LockFileName is the name of the lock file LockFileName = "commands.lock" // LockFileVersion is the current version of the lock file format LockFileVersion = "1.0" )
Variables ¶
var ( // ErrNotLoaded is returned when operations are attempted before loading the lock file ErrNotLoaded = errors.New("lock file not loaded") // ErrCommandNotFound is returned when a command is not found in the lock file ErrCommandNotFound = errors.New("command not found") // ErrCommandExists is returned when trying to add a command that already exists ErrCommandExists = errors.New("command already exists") )
Common errors
Functions ¶
This section is empty.
Types ¶
type CommandSorter ¶
type CommandSorter struct {
// contains filtered or unexported fields
}
CommandSorter provides different sorting methods for commands
func (CommandSorter) ByInstallDate ¶
func (s CommandSorter) ByInstallDate()
ByInstallDate sorts commands by installation date (newest first)
func (CommandSorter) ByName ¶
func (s CommandSorter) ByName()
ByName sorts commands alphabetically by name
func (CommandSorter) ByUpdateDate ¶
func (s CommandSorter) ByUpdateDate()
ByUpdateDate sorts commands by update date (newest first)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles operations on the commands.lock file
Example ¶
package main
import (
"fmt"
"log"
"github.com/gifflet/ccmd/internal/lock"
"github.com/gifflet/ccmd/internal/models"
)
func main() {
// Create a new lock manager
manager := lock.NewManager("/home/user/.claude/commands")
// Load existing lock file or create new one
if err := manager.Load(); err != nil {
log.Fatal(err)
}
// Add a new command
cmd := &models.Command{
Name: "git-helper",
Version: "1.2.0",
Source: "github.com/example/git-helper",
Metadata: map[string]string{
"author": "Example Author",
"license": "MIT",
},
}
if err := manager.AddCommand(cmd); err != nil {
log.Fatal(err)
}
// Save changes to disk
if err := manager.Save(); err != nil {
log.Fatal(err)
}
// List all installed commands
commands, err := manager.ListCommands()
if err != nil {
log.Fatal(err)
}
for _, cmd := range commands {
fmt.Printf("Command: %s v%s\n", cmd.Name, cmd.Version)
}
}
Output:
func NewManagerWithFS ¶
func NewManagerWithFS(dir string, fileSystem fs.FileSystem) *Manager
NewManagerWithFS creates a new lock file manager with a custom file system
func (*Manager) AddCommand ¶
AddCommand adds a new command to the lock file
func (*Manager) CountCommands ¶
CountCommands returns the total number of installed commands
func (*Manager) ExportCommands ¶
ExportCommands exports all commands as a slice for backup or transfer
func (*Manager) GetCommand ¶
GetCommand retrieves a command from the lock file
func (*Manager) GetCommandsBySource ¶
GetCommandsBySource returns all commands from a specific source
func (*Manager) HasCommand ¶
HasCommand checks if a command exists in the lock file
func (*Manager) ImportCommands ¶
ImportCommands imports commands from a backup or transfer
func (*Manager) ListCommands ¶
ListCommands returns a list of all commands in the lock file
func (*Manager) ListCommandsSorted ¶
ListCommandsSorted returns a sorted list of commands
func (*Manager) RemoveCommand ¶
RemoveCommand removes a command from the lock file
func (*Manager) SearchCommands ¶
SearchCommands returns commands matching the search query
func (*Manager) UpdateCommand ¶
UpdateCommand updates an existing command in the lock file
Example ¶
package main
import (
"log"
"github.com/gifflet/ccmd/internal/lock"
"github.com/gifflet/ccmd/internal/models"
)
func main() {
manager := lock.NewManager("/home/user/.claude/commands")
if err := manager.Load(); err != nil {
log.Fatal(err)
}
// Update a command's version
err := manager.UpdateCommand("git-helper", func(cmd *models.Command) error {
cmd.Version = "1.3.0"
cmd.Metadata["updated"] = "true"
return nil
})
if err != nil {
log.Fatal(err)
}
// Save changes
if err := manager.Save(); err != nil {
log.Fatal(err)
}
}
Output: