Compare commits

...
1 Commits
Author SHA1 Message Date
Zachary Rice 9463ffaa5e fix flag access (#1506) 2024-09-14 04:01:27 -05:00
6 changed files with 35 additions and 33 deletions

No files matched your search

+7 -10
View File
@@ -46,11 +46,13 @@ var detectCmd = &cobra.Command{
}
func runDetect(cmd *cobra.Command, args []string) {
initConfig()
var (
findings []report.Finding
err error
)
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
initConfig(source)
var findings []report.Finding
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
@@ -58,11 +60,6 @@ func runDetect(cmd *cobra.Command, args []string) {
// start timer
start := time.Now()
// grab source
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
detector := Detector(cmd, cfg, source)
// set exit code
+10 -6
View File
@@ -23,7 +23,15 @@ var directoryCmd = &cobra.Command{
}
func runDirectory(cmd *cobra.Command, args []string) {
initConfig()
// grab source
source := "."
if len(args) == 1 {
source = args[0]
if source == "" {
source = "."
}
}
initConfig(source)
var (
findings []report.Finding
err error
@@ -35,11 +43,7 @@ func runDirectory(cmd *cobra.Command, args []string) {
// start timer
start := time.Now()
// grab source
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
detector := Detector(cmd, cfg, source)
// set exit code
+11 -5
View File
@@ -25,12 +25,22 @@ var gitCmd = &cobra.Command{
}
func runGit(cmd *cobra.Command, args []string) {
initConfig()
var (
findings []report.Finding
err error
)
// grab source
source := "."
if len(args) == 1 {
source = args[0]
if source == "" {
source = "."
}
}
initConfig(source)
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
@@ -38,10 +48,6 @@ func runGit(cmd *cobra.Command, args []string) {
start := time.Now()
// grab source
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
detector := Detector(cmd, cfg, source)
// set exit code
+5 -6
View File
@@ -25,18 +25,17 @@ var protectCmd = &cobra.Command{
}
func runProtect(cmd *cobra.Command, args []string) {
initConfig()
var err error
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
initConfig(source)
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
exitCode, _ := cmd.Flags().GetInt("exit-code")
staged, _ := cmd.Flags().GetBool("staged")
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("")
}
start := time.Now()
detector := Detector(cmd, cfg, source)
+1 -5
View File
@@ -86,7 +86,7 @@ func initLog() {
}
}
func initConfig() {
func initConfig(source string) {
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
if err != nil {
log.Fatal().Msg(err.Error())
@@ -106,10 +106,6 @@ func initConfig() {
viper.SetConfigFile(envPath)
log.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
} else {
source, err := rootCmd.Flags().GetString("source")
if err != nil {
log.Fatal().Msg(err.Error())
}
fileInfo, err := os.Stat(source)
if err != nil {
log.Fatal().Msg(err.Error())
+1 -1
View File
@@ -21,7 +21,7 @@ var stdInCmd = &cobra.Command{
}
func runStdIn(cmd *cobra.Command, args []string) {
initConfig()
initConfig(".")
var (
findings []report.Finding
err error