refactor: add git generator for add

Signed-off-by: cpendery <cpendery@vt.edu>
This commit is contained in:
cpendery
2023-09-17 03:22:12 -04:00
parent 32c5ee8a32
commit e1e4af7784
2 changed files with 31 additions and 1 deletions
+30
View File
@@ -1,8 +1,11 @@
package git
import (
"strings"
"github.com/cpendery/clac/autocomplete/generators"
"github.com/cpendery/clac/autocomplete/model"
"github.com/google/uuid"
)
func CommitMessageGenerator() *model.Generator {
@@ -23,3 +26,30 @@ func CommitMessageGenerator() *model.Generator {
"\n",
)
}
func AddFileGenerator() *model.Generator {
return &model.Generator{
Id: uuid.New(),
Script: "git --no-optional-locks status --short",
PostProcess: func(s string) []model.TermSuggestion {
suggestions := []model.TermSuggestion{}
lines := strings.Split(s, "\n")
for _, line := range lines {
baseRune := strings.IndexRune(line, 0)
if baseRune == 'M' || baseRune == 'A' {
continue
}
splits := strings.Split(line, " ")
if len(splits) <= 1 {
continue
}
filename := splits[len(splits)-1]
suggestions = append(suggestions, model.TermSuggestion{
Name: filename,
Description: "Unstaged/Untracked File",
})
}
return suggestions
},
}
}
+1 -1
View File
@@ -2755,7 +2755,7 @@ func init() {
Description: `Add file contents to the index`,
Args: []model.Arg{{
Name: "pathspec",
Generator: nil, // TODO: port over generator
Generator: git.AddFileGenerator(),
IsOptional: true,
IsVariadic: true,
}},