Skip to content

Commit

Permalink
Duplicate code for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmestad committed Dec 6, 2019
1 parent a745fd4 commit 81ea1f2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
)

const (
rootConfigKey string = "root"
runnerConfigKey string = "runner"
runConfigKey string = "run" // alias for runner
runnerArgsConfigKey string = "runner_args"
Expand Down Expand Up @@ -189,6 +190,9 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
files = FilterInclude(files, getCommandIncludeRegexp(hooksGroup, commandName)) // NOTE: confusing option, suppose delete it
files = FilterExclude(files, getCommandExcludeRegexp(hooksGroup, commandName))

cmdRoot := getRoot(hooksGroup, commandName)
files = FilterRelative(files, cmdRoot)

VerbosePrint("Files after filters: \n", files)

files_esc := []string{}
Expand All @@ -207,6 +211,9 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {

runnerArg := strings.Split(runner, " ")
command := exec.Command(runnerArg[0], runnerArg[1:]...)
if cmdRoot != "" {
command.Dir = cmdRoot
}
command.Stdin = os.Stdin
command.Stdout = os.Stdout // win specific
command.Stderr = os.Stderr // win specific
Expand Down Expand Up @@ -397,6 +404,11 @@ func getCommands(hooksGroup string) []string {
return keys
}

func getRoot(hooksGroup string, executableName string) string {
key := strings.Join([]string{hooksGroup, commandsConfigKey, executableName, rootConfigKey}, ".")
return viper.GetString(key)
}

func getCommandIncludeRegexp(hooksGroup, executableName string) string {
key := strings.Join([]string{hooksGroup, commandsConfigKey, executableName, includeConfigKey}, ".")
return viper.GetString(key)
Expand Down Expand Up @@ -487,6 +499,20 @@ func FilterGlob(vs []string, matcher string) []string {
return vsf
}

func FilterRelative(vs []string, matcher string) []string {
if matcher == "" {
return vs
}

vsf := make([]string, 0)
for _, v := range vs {
if strings.HasPrefix(v, matcher) {
vsf = append(vsf, strings.Replace(v, matcher, "./", 1))
}
}
return vsf
}

func FilterInclude(vs []string, matcher string) []string {
if matcher == "" {
return vs
Expand Down

0 comments on commit 81ea1f2

Please sign in to comment.