mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 19:54:24 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9463ffaa5e |
No files matched your search
+7
-10
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -21,7 +21,7 @@ var stdInCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runStdIn(cmd *cobra.Command, args []string) {
|
||||
initConfig()
|
||||
initConfig(".")
|
||||
var (
|
||||
findings []report.Finding
|
||||
err error
|
||||
|
||||
Reference in new issue
Block a user