package main import ( "fmt" "log" "os" "strings" "github.com/urfave/cli" ) /* scan,s [directory-with-.tidelift.yml] configure,c [directory-with-.tidelift.yml] verify [directory-with-.tidelift.yml] */ 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 { directory := getDirectory(c) return scan(directory) }, }, { Name: "verify", Usage: "Verify .tidelift.yml configuration", Action: func(c *cli.Context) error { directory := getDirectory(c) return verify(directory) }, }, { 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 getDirectory(c *cli.Context) string { // Return a directory if it's in the arguments if len(c.Args()) > 0 { return c.Args().First() } return "." } // Scan will scan a directory's manifests for all supported manifest files // then it will upload them to tidelift for scanning func scan(directory string) error { // Show error if no .tidelift.yml file if !verifyTideliftYamlExists(directory) { return cli.NewExitError("no .tidelift.yml at supplied directory path", 6) } fmt.Println(strings.Join(getListOfManifestFilenames(directory), ", ")) // TODO, actually upload scan, don't just print names return nil } // Verify will verify that a .tidelift.yml file has the minimum information // in order to upload a manifest to Tidelift func verify(directory string) error { // Show error if no .tidelift.yml file if !verifyTideliftYamlExists(directory) { return cli.NewExitError("no .tidelift.yml at supplied directory path", 6) } missingKey := passesMinimumRequirements(directory) if missingKey != "" { errorMsg := fmt.Sprintf("Missing key '%s:' in .tidelift.yml", missingKey) return cli.NewExitError(errorMsg, 7) } return nil }