feat(spec): support tool aliases (#107)
closes #57 IRIS now automatically read and suggest internal configuration aliases for Git (`.gitconfig`, `.git/config`) and Cargo (`.cargo/config.toml`) - Added the `Provider` interface and extended registry for CLI tools that define aliases - Git: parse aliases via `git config --show-scope`, supporting raw tab/space separation and scope differentiation - Cargo: traverse the directory tree upwards to root to read the `.cargo/config.toml` configuration - 0ms hot-path caching: key caching is calculated entirely via `os.Stat` mtime (no subprocess spawn) combined with a 2-second TTL window to ensure 0ms latency when typing - Lookup integration: display alias suggestions at the subcommand level and automatically expand aliases as the user enters further arguments (ignore shell pipeline commands starting with `!`)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package alias
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type AliasEntry struct {
|
||||
Name string
|
||||
Expansion string
|
||||
Scope string // "local" | "global"
|
||||
}
|
||||
|
||||
type Provider interface {
|
||||
ToolName() string
|
||||
GetAliases(cwd string) []AliasEntry
|
||||
}
|
||||
|
||||
var (
|
||||
providers = make(map[string]Provider)
|
||||
mu sync.RWMutex
|
||||
)
|
||||
|
||||
func Register(p Provider) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
providers[p.ToolName()] = p
|
||||
}
|
||||
|
||||
// Reset clears the registered providers map, restoring it to its initial empty state.
|
||||
func Reset() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
providers = make(map[string]Provider)
|
||||
}
|
||||
|
||||
func GetProvider(toolName string) Provider {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return providers[toolName]
|
||||
}
|
||||
Reference in New Issue
Block a user