feat: Package for command-line arguments

This commit is contained in:
2024-01-02 21:05:33 +00:00
parent edc6cf37cd
commit 8c39d6f40e
4 changed files with 46 additions and 16 deletions

View File

@@ -0,0 +1,29 @@
package cuiargs
import (
"fmt"
"regexp"
models "gitea.likemath.ru/alex/gogrep/internal/models"
)
// ProcessConsoleArguments fills internal grep config
// Returns error if arguments filling is correct, but arguments are incorrect
// Panics and shows info if arguments are invalid
func ProcessConsoleArguments() (*models.GrepConfigInternal, error) {
res := &models.GrepConfigInternal{}
var err error
pathPattern := "git/hook"
res.PathPattern, err = regexp.Compile(pathPattern)
if err != nil {
return nil, fmt.Errorf("unable to compile path pattern Regexp: %v", pathPattern)
}
textPattern := "the commit"
res.TextPattern, err = regexp.Compile(textPattern)
if err != nil {
return nil, fmt.Errorf("unable to compile text pattern Regexp: %v", textPattern)
}
return res, nil
}