chdir
This commit is contained in:
parent
8684aedbc2
commit
104aa44ef5
5
main.go
5
main.go
@ -9,6 +9,11 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
scan,s [directory-with-.tidelift.yml]
|
||||||
|
configure,c [directory-with-.tidelift.yml]
|
||||||
|
*/
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
)
|
)
|
||||||
@ -112,10 +113,11 @@ func manifestGlobs() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getListOfManifestFilenames(directory string) []string {
|
func getListOfManifestFilenames(directory string) []string {
|
||||||
|
os.Chdir(directory)
|
||||||
matchingFiles := make([]string, 0)
|
matchingFiles := make([]string, 0)
|
||||||
|
|
||||||
for _, glob := range manifestGlobs() {
|
for _, glob := range manifestGlobs() {
|
||||||
pathGlob := fmt.Sprintf("%s/**/%s", directory, glob)
|
pathGlob := fmt.Sprintf("**/%s", glob)
|
||||||
files := getListOfGlobMatches(pathGlob)
|
files := getListOfGlobMatches(pathGlob)
|
||||||
|
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -9,11 +10,12 @@ import (
|
|||||||
|
|
||||||
func TestGetListOfGlobMatches(t *testing.T) {
|
func TestGetListOfGlobMatches(t *testing.T) {
|
||||||
//assert getManifestMatches gets all requirements.txt
|
//assert getManifestMatches gets all requirements.txt
|
||||||
|
os.Chdir("test/fixtures")
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"test/fixtures/subdir/requirements.txt",
|
"subdir/requirements.txt",
|
||||||
"test/fixtures/a/b/c/d/e/f/g/requirements.txt",
|
"a/b/c/d/e/f/g/requirements.txt",
|
||||||
}
|
}
|
||||||
got := getListOfGlobMatches("test/**/requirements.txt")
|
got := getListOfGlobMatches("**/requirements.txt")
|
||||||
sort.Strings(expected)
|
sort.Strings(expected)
|
||||||
sort.Strings(got)
|
sort.Strings(got)
|
||||||
|
|
||||||
@ -22,12 +24,12 @@ func TestGetListOfGlobMatches(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetListOfManifestFilenames(t *testing.T) {
|
func TestGetListOfManifestFilenames(t *testing.T) {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"test/fixtures/yarn.lock",
|
"yarn.lock",
|
||||||
"test/fixtures/Gemfile",
|
"Gemfile",
|
||||||
"test/fixtures/a/b/c/d/e/f/g/requirements.txt",
|
"a/b/c/d/e/f/g/requirements.txt",
|
||||||
"test/fixtures/subdir/requirements.txt",
|
"subdir/requirements.txt",
|
||||||
}
|
}
|
||||||
got := getListOfManifestFilenames("test/")
|
got := getListOfManifestFilenames("test/fixtures")
|
||||||
|
|
||||||
sort.Strings(expected)
|
sort.Strings(expected)
|
||||||
sort.Strings(got)
|
sort.Strings(got)
|
||||||
|
Loading…
Reference in New Issue
Block a user