Skip to content

Commit

Permalink
Merge pull request #44 from crashappsec/nettrino/version
Browse files Browse the repository at this point in the history
add version and consistent casing in --help
  • Loading branch information
nettrino authored Oct 20, 2022
2 parents 76167ce + d2fb441 commit ec552af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
37 changes: 23 additions & 14 deletions cmd/github-analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,47 +135,56 @@ func runCmd() {
func NewRootCommand() *cobra.Command {
rootCmd := &cobra.Command{
Use: fmt.Sprintf(
"github-analyzer (v%s)",
"github-analyzer (%s)",
strings.TrimSuffix(version, "\n"),
),
Short: "A tool to collect and highlight potential security issues with a GitHub org",
Long: "A tool to collect and highlight potential security issues with a GitHub org",
Short: "A tool to collect statistics and highlight potential security issues within a GitHub org",
Long: "A tool to collect statistics and highlight potential security issues within a GitHub org",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// You can bind cobra and viper in a few locations, but PersistencePreRunE on the root command works well
return initializeConfig(cmd)
},
PreRun: func(cmd *cobra.Command, args []string) {
onlyPrintVersion, _ := cmd.Flags().GetBool("version")
if onlyPrintVersion {
fmt.Println(version)
os.Exit(0)
}
cmd.MarkFlagRequired("organization")
},
Run: func(cmd *cobra.Command, args []string) {
runCmd()
},
}
// TODO allow auditing a repo/user account only
rootCmd.Flags().
StringVarP(&config.ViperEnv.Organization, "organization", "", "", "The organization we want to check the security on")
rootCmd.MarkFlagRequired("organization")
StringVarP(&config.ViperEnv.Organization, "organization", "", "", "the GitHub organization to be analyzed")

rootCmd.Flags().
StringVarP(&config.ViperEnv.CfgFile, "config", "c", "", "config file (default is $HOME/.github-analyzer.yaml)")
rootCmd.Flags().
StringVarP(&config.ViperEnv.OutputDir, "output", "o", "output", "The directory containing the artifacts of the analysis")
StringVarP(&config.ViperEnv.OutputDir, "output", "o", "output", "the directory containing the artifacts of the analysis")
rootCmd.Flags().
StringVarP(&config.ViperEnv.ScmURL, "scmUrl", "", "", "The API URL for the source control management software you want to check")
StringVarP(&config.ViperEnv.ScmURL, "scmUrl", "", "", "the API URL for the source control management software you want to check")
rootCmd.Flags().
StringVarP(&config.ViperEnv.Token, "token", "", "", fmt.Sprintf("The github token for API authentication (default is $%s_TOKEN)", config.ViperEnvPrefix))
StringVarP(&config.ViperEnv.Token, "token", "", "", fmt.Sprintf("the github token for API authentication (default is $%s_TOKEN)", config.ViperEnvPrefix))

rootCmd.Flags().
BoolVarP(&config.ViperEnv.EnableStats, "enableStats", "", false, "Enable statistic-only reports (might be slow due to throttling limits)")
BoolVarP(&config.ViperEnv.Version, "version", "", false, "print version and exit")
rootCmd.Flags().
BoolVarP(&config.ViperEnv.EnableStats, "enableStats", "", false, "enable user permission statistics (might be slow due to throttling limits)")

rootCmd.Flags().
BoolVarP(&config.ViperEnv.EnableScraping, "enableScraping", "", false, "Enable experimental checks that rely on screen scraping")
BoolVarP(&config.ViperEnv.EnableScraping, "enableScraping", "", false, "enable experimental checks that rely on screen scraping")
rootCmd.Flags().
StringVarP(&config.ViperEnv.Username, "username", "u", "", fmt.Sprintf("Username (required if enableScraping is set) (default is $%s_USERNAME)", config.ViperEnvPrefix))
StringVarP(&config.ViperEnv.Username, "username", "u", "", fmt.Sprintf("username (required if enableScraping is set) (default is $%s_USERNAME)", config.ViperEnvPrefix))
rootCmd.Flags().
StringVarP(&config.ViperEnv.Password, "password", "p", "", fmt.Sprintf("Password (required if enableScraping is set) (default is $%s_PASSWORD)", config.ViperEnvPrefix))
StringVarP(&config.ViperEnv.Password, "password", "p", "", fmt.Sprintf("password (required if enableScraping is set) (default is $%s_PASSWORD)", config.ViperEnvPrefix))
rootCmd.Flags().
StringVarP(&config.ViperEnv.OtpSeed, "otpSeed", "", "", fmt.Sprintf("One Time Password (required if enableScraping is set) (default is $%s_OTP_SEED)", config.ViperEnvPrefix))
StringVarP(&config.ViperEnv.OtpSeed, "otpSeed", "", "", fmt.Sprintf("one Time Password (required if enableScraping is set) (default is $%s_OTP_SEED)", config.ViperEnvPrefix))

rootCmd.Flags().
IntVarP(&config.ViperEnv.Port, "port", "", 3000, "Port for local http server used to display HTML with summary of findings (if you are using docker you will need to override the default port appropriately)")
IntVarP(&config.ViperEnv.Port, "port", "", 3000, "port for local http server used to display HTML with summary of findings (if you are using docker you will need to override the default port appropriately)")
return rootCmd
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/github-analyzer/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.2-pre-alpha-6-g5c5e9c9
v0.1.3-pre-alpha-0-g76167ce
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ViperEnvVars struct {
CfgFile string `mapstructure:"CFG_FILE"`
EnableScraping bool `mapstructure:"ENABLE_SCRAPING"`
EnableStats bool `mapstructure:"ENABLE_STATS"`
Version bool `mapstructure:"VERSION"`
Organization string `mapstructure:"ORGANIZATION"`
OtpSeed string `mapstructure:"OTP_SEED"`
OutputDir string `mapstructure:"OUTPUT_DIR"`
Expand Down

0 comments on commit ec552af

Please sign in to comment.