Files
wehub-resource-sync 48b3ccf279
Test / test (windows-latest) (push) Waiting to run
gitleaks / gitleaks (push) Has been skipped
Test / test (ubuntu-latest) (push) Failing after 0s
chore: import upstream snapshot with attribution
2026-07-13 12:12:29 +08:00

55 lines
1.0 KiB
Go

package cmd
import (
"os"
"time"
"github.com/spf13/cobra"
"github.com/zricethezav/gitleaks/v8/logging"
"github.com/zricethezav/gitleaks/v8/sources"
)
func init() {
rootCmd.AddCommand(stdInCmd)
}
var stdInCmd = &cobra.Command{
Use: "stdin",
Short: "detect secrets from stdin",
Run: runStdIn,
}
func runStdIn(cmd *cobra.Command, _ []string) {
// start timer
start := time.Now()
// setup config (aka, the thing that defines rules)
initConfig(".")
initDiagnostics()
cfg := Config(cmd)
// create detector
detector := Detector(cmd, cfg, "")
// parse flag(s)
exitCode := mustGetIntFlag(cmd, "exit-code")
findings, err := detector.DetectSource(
cmd.Context(),
&sources.File{
Content: os.Stdin,
MaxArchiveDepth: detector.MaxArchiveDepth,
},
)
if err != nil {
// log fatal to exit, no need to continue since a report will not be
// generated when scanning from a pipe...for now
logging.Fatal().Err(err).Msg("failed scan input from stdin")
}
findingSummaryAndExit(detector, findings, exitCode, start, err)
}