From 4de6f207d97018115c3e5c91bb3d689b652ceb6a Mon Sep 17 00:00:00 2001 From: knbr13 Date: Wed, 5 Jun 2024 23:10:53 +0300 Subject: [PATCH 1/3] use path flag instead of prompting the user --- main.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index ba210b2..06dfdf4 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "flag" "fmt" "os" @@ -13,11 +12,18 @@ import ( ) func main() { - var email string + wd, err := os.Getwd() + if err != nil { + fmt.Fprint(os.Stderr, color.Red.Sprintf("gitcs: error: %s\n", err.Error())) + os.Exit(1) + } + + var email, path string var sinceflag, untilflag string flag.StringVar(&sinceflag, "since", "", "start date") flag.StringVar(&untilflag, "until", "", "end date") flag.StringVar(&email, "email", strings.TrimSpace(getGlobalEmailFromGit()), "you Git email") + flag.StringVar(&path, "path", wd, "folder path to scan") flag.Parse() b, err := setTimeFlags(sinceflag, untilflag) @@ -31,20 +37,13 @@ func main() { os.Exit(1) } - reader := bufio.NewReader(os.Stdin) - folder, err := getPathFromUser(reader) - if err != nil { - fmt.Fprint(os.Stderr, color.Red.Sprintf("gitcs: error reading input: %s\n", err.Error())) - os.Exit(1) - } - s := spinner.New(spinner.CharSets[6], 100*time.Millisecond, spinner.WithSuffix(" loading...")) s.Color("green") s.Start() defer s.Stop() - repos, err := scanGitFolders(folder) + repos, err := scanGitFolders(path) if err != nil { fmt.Fprint(os.Stderr, color.Red.Sprintf("\ngitcs: error: %s\n", err.Error())) s.Stop() From 65212da1d12430287276101ce965e706e38dfe9c Mon Sep 17 00:00:00 2001 From: knbr13 Date: Wed, 5 Jun 2024 23:11:04 +0300 Subject: [PATCH 2/3] delete unused functions --- input.go | 24 ------------------------ input_test.go | 43 ------------------------------------------- 2 files changed, 67 deletions(-) delete mode 100644 input.go delete mode 100644 input_test.go diff --git a/input.go b/input.go deleted file mode 100644 index 54cc2c2..0000000 --- a/input.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "strings" - - "github.com/gookit/color" -) - -func getPathFromUser(reader *bufio.Reader) (string, error) { - for { - fmt.Print("enter the folder path to scan for Git repositories: ") - input, err := reader.ReadString('\n') - if err != nil { - return "", err - } - input = strings.TrimSpace(input) - if isValidFolderPath(input) { - return input, nil - } - fmt.Println(color.Yellow.Sprintf("gitcs: path %q is not found, please enter a valid folder path", input)) - } -} diff --git a/input_test.go b/input_test.go deleted file mode 100644 index 4cdc914..0000000 --- a/input_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "bufio" - "strings" - "testing" -) - -func TestGetPathFromUser(t *testing.T) { - testCases := []struct { - description string - input string - expectedPath string - expectedError bool - }{ - { - description: "Valid folder path", - input: "./test_data", - expectedPath: "./test_data", - expectedError: false, - }, - { - description: "Invalid folder path", - input: "./path/to/invalid/folder", - expectedPath: "./", - expectedError: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { - reader := bufio.NewReader(strings.NewReader(tc.input + "\n")) - actualPath, err := getPathFromUser(reader) - if err != nil && !tc.expectedError { - t.Errorf("getPathFromUser() error = %v, want %v", err, tc.expectedError) - } - - if !tc.expectedError && actualPath != tc.expectedPath { - t.Errorf("Expected path: %s, got: %s", tc.expectedPath, actualPath) - } - }) - } -} From 388eee8fd40cf591ac0802f5d883d4236c53dc76 Mon Sep 17 00:00:00 2001 From: knbr13 Date: Wed, 5 Jun 2024 23:16:37 +0300 Subject: [PATCH 3/3] update readme file --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 82bc69b..2a27798 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,11 @@ By default, the tool displays commits from the last 6 months, but you can config > gitcs -since "2023-10-24" -until "2024-01-15" ``` +By default, the tool displays the commits made in your working directory (the directory where you at while running the tool), you can use the -path flag to specify the path to scan for commits in. +```bash +> gitcs -path "/home/username/dev" +``` + - If no global Git email is set on your machine, then you have to specify it using the `-email` flag. - The since and until flags don't need to be specified together.