refactor(commands): separate commands and its core into two folders (#32)

- I think it would be better if one for commands only, one for the spec
handling core logic so people won't be confused by the core logic inside
the commands folder (cleaner I guess)
- Regen docs
This commit is contained in:
VERSE
2026-07-05 11:27:30 +07:00
committed by GitHub
parent 6b98455957
commit ebde9ba68f
536 changed files with 2241 additions and 2241 deletions
+68
View File
@@ -0,0 +1,68 @@
package spec
import (
"strings"
)
// SplitAliasTokens parses the input string into shell-like tokens handling quotes
// example: SplitAliasTokens("git commit -m \"hello world\"")
func Tokenize(s string) []string {
tokens := []string{}
var current strings.Builder
inQuote := false
var quoteChar rune
escaped := false
for _, c := range s {
if escaped {
current.WriteRune(c)
escaped = false
continue
}
switch {
case c == '\\':
escaped = true
case !inQuote && (c == '"' || c == '\''):
inQuote = true
quoteChar = c
case inQuote && c == quoteChar:
inQuote = false
case c == ' ' && !inQuote:
if current.Len() > 0 {
tokens = append(tokens, current.String())
current.Reset()
}
default:
current.WriteRune(c)
}
}
tokens = append(tokens, current.String())
return tokens
}
// HasPrefix checks if s starts with prefix using case-insensitive matching
func HasPrefix(s, prefix string) bool {
if len(prefix) > len(s) {
return false
}
for i := 0; i < len(prefix); i++ {
a, b := s[i], prefix[i]
if a >= 'A' && a <= 'Z' {
a += 32
}
if b >= 'A' && b <= 'Z' {
b += 32
}
if a != b {
return false
}
}
return true
}
// CI = case insensitive
func HasPrefixCI(s, prefix string) bool {
return HasPrefix(s, prefix)
}