Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cmd/git-lzc/lzc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

lazycommit "github.com/spenserblack/git-lazy-commit"
)

var rootCmd = &cobra.Command{
Use: "git-lzc",
Short: "Lazy Commit generates commit messages for you",
Long: `Lazy Commit checks your git status, stages files if they're all unstaged,
and generates a commit message for you.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
repo := lazycommit.Repo(".")

noStaged, err := repo.NoStaged()
onError(err)

if noStaged {
onError(repo.StageAll())
}

out, err := repo.Commit()
onError(err)

fmt.Printf("%s", out)
},
SilenceUsage: true,
}
17 changes: 3 additions & 14 deletions cmd/git-lzc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@ package main
import (
"fmt"
"os"

lazycommit "github.com/spenserblack/git-lazy-commit"
)

func main() {
repo := lazycommit.Repo(".")

noStaged, err := repo.NoStaged()
onError(err)

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

out, err := repo.Commit()
onError(err)

fmt.Printf("%s", out)
}

func onError(err error) {
Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ module github.com/spenserblack/git-lazy-commit

go 1.20

require github.com/cli/safeexec v1.0.1
require (
github.com/cli/safeexec v1.0.1
github.com/spf13/cobra v1.6.1
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=