clean prefixes

This commit is contained in:
Tyrel Souza 2019-05-15 00:07:54 -04:00 committed by Tyrel Souza
parent 33460a3931
commit ccd5d5f0cb
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
4 changed files with 36 additions and 6 deletions

4
go.mod
View File

@ -5,7 +5,11 @@ go 1.12
require (
github.com/bmatcuk/doublestar v1.1.1
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/pmezard/go-difflib v1.0.0
github.com/rakyll/gotest v0.0.0-20180125184505-86f0749cd8cc // indirect
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
gopkg.in/yaml.v2 v2.2.2

14
go.sum
View File

@ -1,12 +1,26 @@
github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rakyll/gotest v0.0.0-20180125184505-86f0749cd8cc h1:hrzpgS8mnUi65ieVrD3TKJMxHP84bzmybMTQIdK/XhM=
github.com/rakyll/gotest v0.0.0-20180125184505-86f0749cd8cc/go.mod h1:iln+RRtJaJ52lKwqrSmNgQYw32Fk16CgChX85eFqBgI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strings"
"github.com/bmatcuk/doublestar"
)
@ -137,5 +138,16 @@ func getListOfGlobMatches(directory string, glob string) []string {
if err != nil {
log.Fatal(err)
}
files = stripDirectory(directory, files)
return files
}
func stripDirectory(directory string, paths []string) []string {
var cleaned []string
for _, path := range paths {
cleaned = append(cleaned, strings.TrimPrefix(path, directory+"/"))
}
return cleaned
}

View File

@ -10,8 +10,8 @@ import (
func TestGetListOfGlobMatches(t *testing.T) {
//assert getManifestMatches gets all requirements.txt
expected := []string{
"test/good_config/subdir/requirements.txt",
"test/good_config/a/b/c/d/e/f/g/requirements.txt",
"subdir/requirements.txt",
"a/b/c/d/e/f/g/requirements.txt",
}
got := getListOfGlobMatches("test/good_config", "**/requirements.txt")
@ -23,10 +23,10 @@ func TestGetListOfGlobMatches(t *testing.T) {
func TestGetListOfManifestFilenames(t *testing.T) {
expected := []string{
"test/good_config/yarn.lock",
"test/good_config/Gemfile",
"test/good_config/a/b/c/d/e/f/g/requirements.txt",
"test/good_config/subdir/requirements.txt",
"yarn.lock",
"Gemfile",
"a/b/c/d/e/f/g/requirements.txt",
"subdir/requirements.txt",
}
got := getListOfManifestFilenames("test/good_config")