Skip to content

Commit eb85ad6

Browse files
committed
Update so that you can continue when leave from the diff.
1 parent 97df005 commit eb85ad6

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

main.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"os"
88
"strconv"
99

10+
"github.com/gookit/color"
1011
"github.com/urfave/cli"
1112
"github.com/yasukotelin/git-diffs/git"
12-
"github.com/gookit/color"
1313
)
1414

1515
func main() {
1616
app := cli.NewApp()
1717
app.Name = "git-diffs"
18-
app.Version = "1.3.1"
18+
app.Version = "1.4.0"
1919
app.Description = "The git subcommand that is diff files selector."
2020
app.Action = mainAction
2121

@@ -37,6 +37,21 @@ func mainAction(c *cli.Context) error {
3737
return err
3838
}
3939

40+
for {
41+
isContinue, err := askToSelectFile(stagedFiles, unstagedFiles)
42+
if err != nil {
43+
return err
44+
}
45+
if !isContinue {
46+
break
47+
}
48+
fmt.Println()
49+
}
50+
51+
return nil
52+
}
53+
54+
func askToSelectFile(stagedFiles []git.DiffFile, unstagedFiles []git.DiffFile) (isContinue bool, err error) {
4055
fmt.Println("Staged files:")
4156
fmt.Println()
4257
stagedFilesLen := len(stagedFiles)
@@ -59,26 +74,27 @@ func mainAction(c *cli.Context) error {
5974
}
6075
fmt.Println()
6176

62-
if (stagedFilesLen + unstagedFilesLen == 0) {
63-
return nil
77+
if stagedFilesLen+unstagedFilesLen == 0 {
78+
return false, nil
6479
}
65-
80+
6681
fmt.Print("Select number (empty is cancel) => ")
6782

6883
var selNumStr string
6984
fmt.Scanln(&selNumStr)
7085

7186
if selNumStr == "" {
72-
return nil
87+
return false, nil
7388
}
7489
selNum, err := strconv.Atoi(selNumStr)
7590
if err != nil {
76-
return errors.New("your input is not number.")
91+
return false, errors.New("your input is not number.")
7792
}
7893
if selNum > stagedFilesLen+unstagedFilesLen || selNum < 1 {
79-
return errors.New("your input is out of range numbers")
94+
return false, errors.New("your input is out of range numbers")
8095
}
8196

97+
fmt.Println()
8298
if selNum <= stagedFilesLen {
8399
// User selected staged file number
84100
err = git.Diff(stagedFiles[selNum-1].Path, true)
@@ -87,8 +103,8 @@ func mainAction(c *cli.Context) error {
87103
err = git.Diff(unstagedFiles[selNum-stagedFilesLen-1].Path, false)
88104
}
89105
if err != nil {
90-
return err
106+
return false, err
91107
}
92108

93-
return nil
109+
return true, nil
94110
}

0 commit comments

Comments
 (0)