Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to print feature flags in analyze script #820

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion cmd/analyze/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"os"
"strings"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"

"github.com/ossf/package-analysis/internal/analysis"
"github.com/ossf/package-analysis/internal/featureflags"
"github.com/ossf/package-analysis/internal/log"
Expand Down Expand Up @@ -35,7 +38,8 @@ var (
customSandbox = flag.String("sandbox-image", "", "override default dynamic analysis sandbox with custom image")
customAnalysisCmd = flag.String("analysis-command", "", "override default dynamic analysis script path (use with custom sandbox image)")
listModes = flag.Bool("list-modes", false, "prints out a list of available analysis modes")
features = flag.String("feature-flags", "", "override default feature flag settings")
features = flag.String("features", "", "override features that are enabled/disabled by default")
listFeatures = flag.Bool("list-features", false, "list available features that can be toggled")
help = flag.Bool("help", false, "print help on available options")
analysisMode = utils.CommaSeparatedFlags("mode", []string{"static", "dynamic"},
"list of analysis modes to run, separated by commas. Use -list-modes to see available options")
Expand Down Expand Up @@ -83,6 +87,25 @@ func printAnalysisModes() {
fmt.Println()
}

func printFeatureFlags() {
fmt.Printf("Feature List\n\n")
fmt.Printf("%-30s %s\n", "Name", "Default")
fmt.Printf("----------------------------------------\n")

// print features in sorted order
state := featureflags.State()
sortedFeatures := maps.Keys(state)
slices.Sort(sortedFeatures)

// print Off/On rather than 'false' and 'true'
stateStrings := map[bool]string{false: "Off", true: "On"}
for _, feature := range sortedFeatures {
fmt.Printf("%-30s %s\n", feature, stateStrings[state[feature]])
}

fmt.Println()
}

// makeSandboxOptions prepares options for the sandbox based on command line arguments.
//
// In particular:
Expand Down Expand Up @@ -180,6 +203,11 @@ func main() {
return
}

if *listFeatures {
printFeatureFlags()
return
}

if ecosystem == pkgecosystem.None {
flag.Usage()
return
Expand Down