tideliftcli/main.go

62 lines
1.1 KiB
Go
Raw Normal View History

2019-05-14 02:24:02 +00:00
package main
import (
"fmt"
"log"
"os"
2019-05-14 02:52:22 +00:00
"strings"
2019-05-14 02:24:02 +00:00
2019-05-14 02:52:22 +00:00
"github.com/bmatcuk/doublestar"
2019-05-14 02:24:02 +00:00
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "upload",
Aliases: []string{"u"},
Usage: "Upload a directory's manifests",
Action: func(c *cli.Context) error {
2019-05-14 02:52:22 +00:00
return upload(c)
2019-05-14 02:24:02 +00:00
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
2019-05-14 02:52:22 +00:00
func upload(c *cli.Context) error {
directory := c.Args().First()
2019-05-14 03:26:13 +00:00
fmt.Println(strings.Join(getAllManifests(directory), ", "))
// TODO, actually upload, don't just print names
return nil
}
func getAllManifests(directory string) []string {
2019-05-14 02:52:22 +00:00
matchingFiles := make([]string, 0)
for _, glob := range manifestGlobs() {
2019-05-14 03:26:13 +00:00
pathGlob := fmt.Sprintf("%s/**/%s", directory, glob)
files := getManifestGlobMatches(pathGlob)
2019-05-14 02:52:22 +00:00
if len(files) > 0 {
matchingFiles = append(matchingFiles, files...)
}
}
2019-05-14 03:26:13 +00:00
return matchingFiles
2019-05-14 02:52:22 +00:00
}
2019-05-14 03:26:13 +00:00
func getManifestGlobMatches(glob string) []string {
2019-05-14 02:52:22 +00:00
files, err := doublestar.Glob(glob)
if err != nil {
log.Fatal(err)
}
return files
}