feat: Package for command-line arguments
This commit is contained in:
29
internal/cui-args/args_reader.go
Normal file
29
internal/cui-args/args_reader.go
Normal 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
|
||||
}
|
||||
9
internal/models/config.go
Normal file
9
internal/models/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package models
|
||||
|
||||
import "regexp"
|
||||
|
||||
// GrepConfigInternal defines valid grep configuration after parameters parsing
|
||||
type GrepConfigInternal struct {
|
||||
PathPattern *regexp.Regexp
|
||||
TextPattern *regexp.Regexp
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// ProcessSingleFile processes file and send it Result to channel
|
||||
func ProcessSingleFile(rePattern regexp.Regexp, path string, out chan models.FileMatchData) {
|
||||
func ProcessSingleFile(rePattern *regexp.Regexp, path string, out chan models.FileMatchData) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user