tideliftcli/main.go
2019-05-15 22:41:12 -04:00

62 lines
1.1 KiB
Go

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