Skip to content

Commit

Permalink
Merge pull request #2 from d-kuro/feature/delete-logger
Browse files Browse the repository at this point in the history
Remove logger.
  • Loading branch information
d-kuro committed Dec 25, 2018
2 parents 1183f34 + d6621aa commit 66648f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
35 changes: 17 additions & 18 deletions cmd/kusa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"syscall"
"time"

"github.com/d-kuro/kusa/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
"golang.org/x/crypto/ssh/terminal"
Expand Down Expand Up @@ -47,7 +46,7 @@ var (
Long: "Create GitHub contribution on date specified by date option",
Run: func(cmd *cobra.Command, args []string) {
if err := createKusa(); err != nil {
log.Error("create GitHub contribution error", zap.Error(err))
logger.Error("create GitHub contribution error", zap.Error(err))
}
},
}
Expand All @@ -56,23 +55,23 @@ var (
func createKusa() error {
repo, err := git.PlainOpen(repoDir)
if err != nil {
log.Error("open git repository error", zap.String("dir_path", repoDir), zap.Error(err))
logger.Error("open git repository error", zap.String("dir_path", repoDir), zap.Error(err))
return err
}

wt, err := repo.Worktree()
if err != nil {
log.Error("failed to get work tree", zap.Error(err))
logger.Error("failed to get work tree", zap.Error(err))
return err
}

time, err := time.ParseInLocation(layout, date, time.Local)
if err != nil {
log.Error("time parse error", zap.String("date", date), zap.Error(err))
logger.Error("time parse error", zap.String("date", date), zap.Error(err))
return err
}

log.Info("execute commit",
logger.Info("execute commit",
zap.String("name", name), zap.String("e-mail", mail),
zap.String("date", date), zap.String("commit_message", commitMsg))
commit, err := wt.Commit(commitMsg, &git.CommitOptions{
Expand All @@ -83,31 +82,31 @@ func createKusa() error {
},
})
if err != nil {
log.Error("commit error", zap.Error(err))
logger.Error("commit error", zap.Error(err))
return err
}
log.Info("complete commit", zap.String("commit_hash", commit.String()))
logger.Info("complete commit", zap.String("commit_hash", commit.String()))

log.Info("input credential")
logger.Info("input credential")
auth, err := inputCredentials()
if err != nil {
log.Error("failed read credentials", zap.Error(err))
logger.Error("failed read credentials", zap.Error(err))
// rollback reset empty commit
rollbackCommit(wt, commit)
return err
}

log.Info("execute push", zap.String("repository", repoDir))
logger.Info("execute push", zap.String("repository", repoDir))
if err := repo.Push(&git.PushOptions{
Auth: auth,
Progress: os.Stdout,
}); err != nil {
log.Error("push error", zap.Error(err))
logger.Error("push error", zap.Error(err))
// rollback reset empty commit
rollbackCommit(wt, commit)
return err
}
log.Info("complete push")
logger.Info("complete push")

return nil
}
Expand All @@ -118,7 +117,7 @@ func inputCredentials() (transport.AuthMethod, error) {
// new line
fmt.Println()
if err != nil {
log.Error("failed read user name", zap.Error(err))
logger.Error("failed read user name", zap.Error(err))
return nil, err
}

Expand All @@ -127,7 +126,7 @@ func inputCredentials() (transport.AuthMethod, error) {
// new line
fmt.Println()
if err != nil {
log.Error("failed read password", zap.Error(err))
logger.Error("failed read password", zap.Error(err))
return nil, err
}

Expand All @@ -138,12 +137,12 @@ func inputCredentials() (transport.AuthMethod, error) {
}

func rollbackCommit(wt *git.Worktree, commit plumbing.Hash) {
log.Info("rollback reset commit", zap.String("commit_hash", commit.String()))
logger.Info("rollback reset commit", zap.String("commit_hash", commit.String()))
if err := wt.Reset(&git.ResetOptions{
Commit: commit,
}); err != nil {
log.Error("failed rollback reset commit",
logger.Error("failed rollback reset commit",
zap.String("commit_hash", commit.String()), zap.Error(err))
}
log.Info("complete reset commit", zap.String("commit_hash", commit.String()))
logger.Info("complete reset commit", zap.String("commit_hash", commit.String()))
}
23 changes: 12 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import (
"fmt"
"os"

"github.com/d-kuro/kusa/log"
"go.uber.org/zap"

"github.com/spf13/cobra"
"go.uber.org/zap"
)

func init() {
cobra.OnInitialize()
}

var rootCmd = &cobra.Command{
Use: "kusa",
Run: func(cmd *cobra.Command, args []string) {
kusa := `_ _ _ _ ____ ____
var (
logger, _ = zap.NewDevelopment()
rootCmd = &cobra.Command{
Use: "kusa",
Run: func(cmd *cobra.Command, args []string) {
kusa := `_ _ _ _ ____ ____
|_/ | | [__ |__|
| \_ |__| ___] | |`
fmt.Println(kusa)
},
}
fmt.Println(kusa)
},
}
)

func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Error("failed execute command", zap.Error(err))
logger.Error("failed execute command", zap.Error(err))
os.Exit(1)
}
}
9 changes: 0 additions & 9 deletions log/log.go

This file was deleted.

0 comments on commit 66648f7

Please sign in to comment.