From 4f6db49d41a6135450bc1315645e31d571b5543c Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 13 May 2019 22:52:22 -0400 Subject: [PATCH] manifests listing --- main.go | 36 ++++++- manifests.go | 99 -------------------- test/fixtures/Gemfile | 0 test/fixtures/a/b/c/d/e/f/g/requirements.txt | 0 test/fixtures/subdir/requirements.txt | 0 test/fixtures/yarn.lock | 0 6 files changed, 32 insertions(+), 103 deletions(-) delete mode 100644 manifests.go create mode 100644 test/fixtures/Gemfile create mode 100644 test/fixtures/a/b/c/d/e/f/g/requirements.txt create mode 100644 test/fixtures/subdir/requirements.txt create mode 100644 test/fixtures/yarn.lock diff --git a/main.go b/main.go index 594566d..e3cc5a9 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,9 @@ import ( "fmt" "log" "os" + "strings" + "github.com/bmatcuk/doublestar" "github.com/urfave/cli" ) @@ -17,8 +19,7 @@ func main() { Aliases: []string{"u"}, Usage: "Upload a directory's manifests", Action: func(c *cli.Context) error { - fmt.Println(getManifests()) - return nil + return upload(c) }, }, } @@ -29,8 +30,35 @@ func main() { } } -func getManifests() []string { - globs := make([]string, 66) // Increment when adding new manifest types +func upload(c *cli.Context) error { + directory := c.Args().First() + matchingFiles := make([]string, 0) + + for _, glob := range manifestGlobs() { + globPattern := []string{directory, "**", glob} + pathGlob := strings.Join(globPattern, "/") + files := getManifestMatches(pathGlob) + + if len(files) > 0 { + matchingFiles = append(matchingFiles, files...) + } + } + + fmt.Println(strings.Join(matchingFiles, ", ")) + return nil +} + +func getManifestMatches(glob string) []string { + files, err := doublestar.Glob(glob) + if err != nil { + log.Fatal(err) + } + return files +} + +func manifestGlobs() []string { + + globs := make([]string, 0) // Hackage globs = append(globs, "*.cabal") diff --git a/manifests.go b/manifests.go deleted file mode 100644 index 174745a..0000000 --- a/manifests.go +++ /dev/null @@ -1,99 +0,0 @@ -// package main - -// func getManifests() []string { -// globs := make([]string, 66) // Increment when adding new manifest types - -// // Hackage -// globs = append(globs, "*.cabal") -// // npm -// globs = append(globs, "package.json") -// globs = append(globs, "package-lock.json") -// globs = append(globs, "npm-shrinkwrap.json") -// globs = append(globs, "yarn.lock") -// // Maven -// globs = append(globs, "pom.xml") -// globs = append(globs, "ivy.xml") -// globs = append(globs, "build.gradle") -// // RubyGems -// globs = append(globs, "Gemfile") -// globs = append(globs, "Gemfile.lock") -// globs = append(globs, "gems.rb") -// globs = append(globs, "gems.locked") -// globs = append(globs, "*.gemspec") -// // Packagist -// globs = append(globs, "composer.json") -// globs = append(globs, "composer.lock") -// // PyPi -// globs = append(globs, "setup.py") -// globs = append(globs, "req*.txt") -// globs = append(globs, "req*.pip") -// globs = append(globs, "requirements/*.txt") -// globs = append(globs, "requirements/*.pip") -// globs = append(globs, "Pipfile") -// globs = append(globs, "Pipfile.lock") -// // Nuget -// globs = append(globs, "packages.config") -// globs = append(globs, "Project.json") -// globs = append(globs, "Project.lock.json") -// globs = append(globs, "*.nuspec") -// globs = append(globs, "paket.lock") -// globs = append(globs, "*.csproj") -// // Bower -// globs = append(globs, "bower.json") -// // CPAN -// globs = append(globs, "META.json") -// globs = append(globs, "META.yml") -// // CocoaPods -// globs = append(globs, "Podfile") -// globs = append(globs, "Podfile.lock") -// globs = append(globs, "*.podspec") -// // Clojars -// globs = append(globs, "project.clj") -// // Meteor -// globs = append(globs, "versions.json") -// // CRAN -// globs = append(globs, "DESCRIPTION") -// // Cargo -// globs = append(globs, "Cargo.toml") -// globs = append(globs, "Cargo.lock") -// // Hex -// globs = append(globs, "mix.exs") -// globs = append(globs, "mix.lock") -// // Swift -// globs = append(globs, "Package.swift") -// // Pub -// globs = append(globs, "pubspec.yaml") -// globs = append(globs, "pubspec.lock") -// // Carthage -// globs = append(globs, "Cartfile") -// globs = append(globs, "Cartfile.private") -// globs = append(globs, "Cartfile.resolved") -// // Dub -// globs = append(globs, "dub.json") -// globs = append(globs, "dub.sdl") -// // Julia -// globs = append(globs, "REQUIRE") -// // Shards -// globs = append(globs, "shard.yml") -// globs = append(globs, "shard.lock") -// // Go -// globs = append(globs, "glide.yaml") -// globs = append(globs, "glide.lock") -// globs = append(globs, "Godeps") -// globs = append(globs, "Godeps/Godeps.json") -// globs = append(globs, "vendor/manifest") -// globs = append(globs, "vendor/vendor.json") -// globs = append(globs, "Gopkg.toml") -// globs = append(globs, "Gopkg.lock") -// // Elm -// globs = append(globs, "elm-package.json") -// globs = append(globs, "elm_dependencies.json") -// globs = append(globs, "elm-stuff/exact-dependencies.json") -// // Haxelib -// globs = append(globs, "haxelib.json") -// // Hackage -// globs = append(globs, "*.cabal") -// globs = append(globs, "cabal.config") - -// return globs -// } diff --git a/test/fixtures/Gemfile b/test/fixtures/Gemfile new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/a/b/c/d/e/f/g/requirements.txt b/test/fixtures/a/b/c/d/e/f/g/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/subdir/requirements.txt b/test/fixtures/subdir/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/yarn.lock b/test/fixtures/yarn.lock new file mode 100644 index 0000000..e69de29