Skip to content

Commit

Permalink
fix: remove find command
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Thuilot <[email protected]>
  • Loading branch information
bthuilot committed Nov 17, 2024
1 parent e47dc04 commit ea75ce7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 112 deletions.
60 changes: 0 additions & 60 deletions cmd/find.go

This file was deleted.

38 changes: 6 additions & 32 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,12 @@ import (
"github.com/spf13/cobra"
)

var (
/* Flags */
// repoURL is the URL of the git repository to scan
repoURL string
// repoPath is the path to the git repository to scan
repoPath string
// bare is a flag to clone or import the repository as a bare repository
bare bool
// keepRefs is a flag to keep refs created for dangling commits
keepRefs bool
// cleanup is a flag to remove the cloned repo after scanning
// NOTE: only valid when --repo-url is set
cleanup bool
// logLevel is the log level for the application
logLevel string
)
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

var rootCmd = &cobra.Command{
Use: "git-lost-and-found",
Expand All @@ -45,22 +35,6 @@ This allows for scanners that use 'git log' to search blob data to not miss any

func init() {
rootCmd.SetErrPrefix("ERROR: ")
scanCmd.PersistentFlags().BoolVarP(&bare, "bare", "b", true, "clone or import the repository as a bare repository")
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "log level (debug, info, warn, error, fatal, panic)")
rootCmd.PersistentFlags().StringVarP(&repoURL, "repo-url", "r", "", "URL of the git repository to scan")
rootCmd.PersistentFlags().StringVarP(&repoPath, "repo-path", "p", "", "Path to the git repository to scan")
rootCmd.PersistentFlags().BoolVarP(&keepRefs, "keep-refs", "k", false, "Keep refs created for dangling commits")
rootCmd.PersistentFlags().BoolVarP(&cleanup, "cleanup", "c", false, "Remove the cloned repository after scanning")
_ = rootCmd.MarkPersistentFlagFilename("repo-path")
rootCmd.MarkFlagsMutuallyExclusive("repo-url", "repo-path")
rootCmd.MarkFlagsOneRequired("repo-url", "repo-path")
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func getGitRepository() (*gogit.Repository, string, func(), error) {
Expand Down
27 changes: 27 additions & 0 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,34 @@ import (
"github.com/spf13/cobra"
)

var (
/* Flags */
// repoURL is the URL of the git repository to scan
repoURL string
// repoPath is the path to the git repository to scan
repoPath string
// bare is a flag to clone or import the repository as a bare repository
bare bool
// keepRefs is a flag to keep refs created for dangling commits
keepRefs bool
// cleanup is a flag to remove the cloned repo after scanning
// NOTE: only valid when --repo-url is set
cleanup bool
// logLevel is the log level for the application
logLevel string
)

func init() {
scanCmd.Flags().BoolVarP(&bare, "bare", "b", true, "clone or import the repository as a bare repository")
scanCmd.Flags().StringVarP(&logLevel, "log-level", "l", "info", "log level (debug, info, warn, error, fatal, panic)")
scanCmd.Flags().StringVarP(&repoURL, "repo-url", "r", "", "URL of the git repository to scan")
scanCmd.Flags().StringVarP(&repoPath, "repo-path", "p", "", "Path to the git repository to scan")
scanCmd.Flags().BoolVarP(&keepRefs, "keep-refs", "k", false, "Keep refs created for dangling commits")
scanCmd.Flags().BoolVarP(&cleanup, "cleanup", "c", false, "Remove the cloned repository after scanning")
_ = scanCmd.MarkFlagFilename("repo-path")
scanCmd.MarkFlagsMutuallyExclusive("repo-url", "repo-path")
scanCmd.MarkFlagsOneRequired("repo-url", "repo-path")

rootCmd.AddCommand(scanCmd)
}

Expand Down
18 changes: 0 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
package main

import (
"os"

"github.com/bthuilot/git-lost-and-found/cmd"
"github.com/sirupsen/logrus"
)

func init() {
lvl, ok := os.LookupEnv("LOG_LEVEL")
// LOG_LEVEL not set, let's default to debug
if !ok {
lvl = "debug"
}
// parse string, this is built-in feature of logrus
ll, err := logrus.ParseLevel(lvl)
if err != nil {
ll = logrus.DebugLevel
}
// set global log level
logrus.SetLevel(ll)
}

func main() {
cmd.Execute()
}
4 changes: 2 additions & 2 deletions pkg/scanning/exec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scanning

import (
"errors"
"github.com/sirupsen/logrus"
"os"
"os/exec"
Expand All @@ -10,7 +9,8 @@ import (

func ExecScanner(dir string, cmdArgs []string) error {
if len(cmdArgs) == 0 {
return errors.New("no scanner command provided")
logrus.Warnf("no scanner command provided, exiting")
return nil
}

for i, arg := range cmdArgs {
Expand Down

0 comments on commit ea75ce7

Please sign in to comment.