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

73 lines
1.3 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{"s"},
Usage: "Scan a directory's manifests",
Action: func(c *cli.Context) error {
if len(c.Args()) > 0 {
return scan(c)
}
return cli.NewExitError("no directory provided", 5)
},
},
{
Name: "configure",
Aliases: []string{"c"},
Usage: "Configure the app",
Action: func(c *cli.Context) error {
return cli.NewExitError("No Configuration provided", 4)
},
},
}
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
}