Skip to content

Commit

Permalink
Merge pull request #55 from ivanilves/with
Browse files Browse the repository at this point in the history
refactor: add WithNameEx() func to wrap arbitrary regex rule
  • Loading branch information
ivanilves committed Apr 24, 2024
2 parents 89a38e0 + a3b4388 commit 7eb0c1d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ vendor/
/cmd/travelgrunt/*
!/cmd/travelgrunt/*.go
/dist/*

# Local Makefile
local.mk
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ NEXT_VERSION = v${API_VERSION}.${NEXT_PATCH}

SHELL := /bin/bash

-include local.mk

default: dep build

all: dep build test install
Expand Down
5 changes: 1 addition & 4 deletions cmd/travelgrunt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

"github.com/ivanilves/travelgrunt/pkg/config"
"github.com/ivanilves/travelgrunt/pkg/config/rule"
"github.com/ivanilves/travelgrunt/pkg/directory"
"github.com/ivanilves/travelgrunt/pkg/directory/tree"
"github.com/ivanilves/travelgrunt/pkg/file"
Expand Down Expand Up @@ -117,9 +116,7 @@ func main() {
}

if expression != "" {
rules := []rule.Rule{{NameEx: expression}}

cfg.Rules = rules
cfg = cfg.WithNameEx(expression)
}

entries, paths, err := directory.Collect(rootPath, cfg)
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/with.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package config

import (
"github.com/ivanilves/travelgrunt/pkg/config/rule"
)

// WithNameEx returns a copy of config with regex-based rule added
func (cfg Config) WithNameEx(nameEx string) Config {
cfg.Rules = []rule.Rule{rule.Rule{NameEx: nameEx}}

return cfg
}
17 changes: 17 additions & 0 deletions pkg/config/with_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestWithNameEx(t *testing.T) {
assert := assert.New(t)

cfg := DefaultConfig()

cfg = cfg.WithNameEx("*.tf")

assert.Len(cfg.Rules, 1)
}

0 comments on commit 7eb0c1d

Please sign in to comment.