feat: scaffold remove command foundations

This commit is contained in:
Rogee
2025-10-29 18:21:01 +08:00
parent ceea09f7be
commit 446bd46b95
25 changed files with 994 additions and 0 deletions

34
internal/remove/parser.go Normal file
View File

@@ -0,0 +1,34 @@
package remove
import "strings"
// ParseArgsResult captures parser output for sequential removals.
type ParseArgsResult struct {
Tokens []string
Duplicates []string
}
// ParseArgs splits, trims, and deduplicates tokens while preserving order.
func ParseArgs(args []string) (ParseArgsResult, error) {
result := ParseArgsResult{Tokens: make([]string, 0, len(args))}
seen := make(map[string]int)
for _, raw := range args {
token := strings.TrimSpace(raw)
if token == "" {
continue
}
if _, exists := seen[token]; exists {
result.Duplicates = append(result.Duplicates, token)
continue
}
seen[token] = len(result.Tokens)
result.Tokens = append(result.Tokens, token)
}
if len(result.Tokens) == 0 {
return ParseArgsResult{}, ErrNoTokens
}
return result, nil
}