Skip to content

Commit

Permalink
Move most code into a 'common' package
Browse files Browse the repository at this point in the history
The 'cli' and the 'daemon' will need to share this code.
  • Loading branch information
vHanda committed May 5, 2022
1 parent 4122acb commit 562ce3f
Show file tree
Hide file tree
Showing 178 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion author.go → common/author.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions autosync.go → common/autosync.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main
package common

import "github.com/ztrue/tracerr"

func autoSync(repoPath string) error {
func AutoSync(repoPath string) error {
var err error
err = ensureGitAuthor(repoPath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion commit.go → common/commit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion commit_test.go → common/commit_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion config.go → common/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion fetch.go → common/fetch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"github.com/ztrue/tracerr"
Expand Down
2 changes: 1 addition & 1 deletion fetch_test.go → common/fetch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion ignore.go → common/ignore.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"path/filepath"
Expand Down
2 changes: 1 addition & 1 deletion ignore_test.go → common/ignore_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion push.go → common/push.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"github.com/ztrue/tracerr"
Expand Down
2 changes: 1 addition & 1 deletion rebase.go → common/rebase.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion rebase_test.go → common/rebase_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"testing"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion watch.go → common/watch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package common

import (
"fmt"
Expand Down
11 changes: 6 additions & 5 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/GitJournal/git-auto-sync/common"
cli "github.com/urfave/cli/v2"
"github.com/ztrue/tracerr"
git "gopkg.in/src-d/go-git.v4"
Expand All @@ -19,7 +20,7 @@ func daemonStatus(ctx *cli.Context) error {
}

func daemonList(ctx *cli.Context) error {
config, err := ReadConfig()
config, err := common.ReadConfig()
if err != nil {
return tracerr.Wrap(err)
}
Expand All @@ -46,13 +47,13 @@ func daemonAdd(ctx *cli.Context) error {
return tracerr.Wrap(err)
}

config, err := ReadConfig()
config, err := common.ReadConfig()
if err != nil {
return tracerr.Wrap(err)
}

config.Repos = append(config.Repos, repoPath)
err = WriteConfig(config)
err = common.WriteConfig(config)
if err != nil {
return tracerr.Wrap(err)
}
Expand Down Expand Up @@ -89,7 +90,7 @@ func daemonRm(ctx *cli.Context) error {
repoPath = filepath.Join(cwd, repoPath)
}

config, err := ReadConfig()
config, err := common.ReadConfig()
if err != nil {
return tracerr.Wrap(err)
}
Expand All @@ -108,7 +109,7 @@ func daemonRm(ctx *cli.Context) error {
}

config.Repos = remove(config.Repos, pos)
err = WriteConfig(config)
err = common.WriteConfig(config)
if err != nil {
return tracerr.Wrap(err)
}
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/gen2brain/beeep"
cli "github.com/urfave/cli/v2"
"github.com/ztrue/tracerr"

"github.com/GitJournal/git-auto-sync/common"
)

func main() {
Expand All @@ -23,7 +25,7 @@ func main() {
return tracerr.Wrap(err)
}

return WatchForChanges(repoPath)
return common.WatchForChanges(repoPath)
},
},
{
Expand All @@ -35,7 +37,7 @@ func main() {
return tracerr.Wrap(err)
}

err = autoSync(repoPath)
err = common.AutoSync(repoPath)
if err != nil {
return tracerr.Wrap(err)
}
Expand Down

0 comments on commit 562ce3f

Please sign in to comment.