Skip to content

Commit

Permalink
refactor flag filter to method
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
  • Loading branch information
jdolitsky committed Jan 13, 2019
1 parent e4f741d commit 6d0a9c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmd/chart-scanner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var (

// Revision is the git commit id (added at compile time)
Revision string

exitCode int
)

func main() {
Expand All @@ -25,17 +27,21 @@ func main() {
app.Name = "chart-scanner"
app.Version = fmt.Sprintf("%s (build %s)", Version, Revision)
app.Usage = "checks a storage directory for evil charts"
app.Flags = buildCliFlags()
app.Action = cliHandler
app.Run(os.Args)
}

func buildCliFlags() []cli.Flag {
var flags []cli.Flag
for _, flag := range config.CLIFlags {
name := flag.GetName()
if name == "debug" || strings.HasPrefix(name, "storage") {
flags = append(flags, flag)
}
}
app.Flags = flags
sort.Sort(cli.FlagsByName(app.Flags))
app.Run(os.Args)
sort.Sort(cli.FlagsByName(flags))
return flags
}

func cliHandler(c *cli.Context) {
Expand All @@ -55,4 +61,6 @@ func cliHandler(c *cli.Context) {

debug := conf.GetBool("debug")
scan(backend, "", debug)

os.Exit(exitCode)
}
3 changes: 3 additions & 0 deletions cmd/chart-scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ func validateChartPackage(filePath string, debug bool) {
if debug {
log.Printf("DEBUG %s is valid\n", filePath)
}

exitCode = 1
log.Printf("ERROR %s is invalid: bad chart name\n", filePath)
}

0 comments on commit 6d0a9c5

Please sign in to comment.