File tree 4 files changed +56
-15
lines changed
4 files changed +56
-15
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/spf13/cobra"
7
+
8
+ lazycommit "github.com/spenserblack/git-lazy-commit"
9
+ )
10
+
11
+ var rootCmd = & cobra.Command {
12
+ Use : "git-lzc" ,
13
+ Short : "Lazy Commit generates commit messages for you" ,
14
+ Long : `Lazy Commit checks your git status, stages files if they're all unstaged,
15
+ and generates a commit message for you.` ,
16
+ Args : cobra .NoArgs ,
17
+ Run : func (cmd * cobra.Command , args []string ) {
18
+ repo := lazycommit .Repo ("." )
19
+
20
+ noStaged , err := repo .NoStaged ()
21
+ onError (err )
22
+
23
+ if noStaged {
24
+ onError (repo .StageAll ())
25
+ }
26
+
27
+ out , err := repo .Commit ()
28
+ onError (err )
29
+
30
+ fmt .Printf ("%s" , out )
31
+ },
32
+ SilenceUsage : true ,
33
+ }
Original file line number Diff line number Diff line change @@ -3,24 +3,13 @@ package main
3
3
import (
4
4
"fmt"
5
5
"os"
6
-
7
- lazycommit "github.com/spenserblack/git-lazy-commit"
8
6
)
9
7
10
8
func main () {
11
- repo := lazycommit .Repo ("." )
12
-
13
- noStaged , err := repo .NoStaged ()
14
- onError (err )
15
-
16
- if noStaged {
17
- onError (repo .StageAll ())
9
+ if err := rootCmd .Execute (); err != nil {
10
+ fmt .Fprintln (os .Stderr , err )
11
+ os .Exit (1 )
18
12
}
19
-
20
- out , err := repo .Commit ()
21
- onError (err )
22
-
23
- fmt .Printf ("%s" , out )
24
13
}
25
14
26
15
func onError (err error ) {
Original file line number Diff line number Diff line change @@ -2,4 +2,12 @@ module github.com/spenserblack/git-lazy-commit
2
2
3
3
go 1.20
4
4
5
- require github.com/cli/safeexec v1.0.1
5
+ require (
6
+ github.com/cli/safeexec v1.0.1
7
+ github.com/spf13/cobra v1.6.1
8
+ )
9
+
10
+ require (
11
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
12
+ github.com/spf13/pflag v1.0.5 // indirect
13
+ )
Original file line number Diff line number Diff line change 1
1
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00 =
2
2
github.com/cli/safeexec v1.0.1 /go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q =
3
+ github.com/cpuguy83/go-md2man/v2 v2.0.2 /go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o =
4
+ github.com/inconshreveable/mousetrap v1.0.1 /go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw =
5
+ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8 =
6
+ github.com/inconshreveable/mousetrap v1.1.0 /go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw =
7
+ github.com/russross/blackfriday/v2 v2.1.0 /go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM =
8
+ github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA =
9
+ github.com/spf13/cobra v1.6.1 /go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY =
10
+ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA =
11
+ github.com/spf13/pflag v1.0.5 /go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg =
12
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
13
+ gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments