rename package s/utils/cmdutil/

This commit is contained in:
Songmu 2019-04-27 23:51:36 +09:00
parent 64113cb647
commit 31d2951692
6 changed files with 32 additions and 32 deletions

View file

@ -1,4 +1,4 @@
package utils
package cmdutil
import (
"fmt"

View file

@ -8,10 +8,10 @@ import (
"path/filepath"
"strings"
"github.com/motemen/ghq/utils"
"github.com/motemen/ghq/cmdutil"
)
func NewFakeRunner(dispatch map[string]error) utils.RunFunc {
func NewFakeRunner(dispatch map[string]error) cmdutil.RunFunc {
return func(cmd *exec.Cmd) error {
cmdString := strings.Join(cmd.Args, " ")
for cmdPrefix, err := range dispatch {

View file

@ -7,7 +7,7 @@ import (
"strings"
"github.com/motemen/ghq/logger"
"github.com/motemen/ghq/utils"
"github.com/motemen/ghq/cmdutil"
)
// A RemoteRepository represents a remote repository.
@ -79,9 +79,9 @@ func (repo *GoogleCodeRepository) IsValid() bool {
}
func (repo *GoogleCodeRepository) VCS() (*VCSBackend, *url.URL) {
if utils.RunSilently("hg", "identify", repo.url.String()) == nil {
if cmdutil.RunSilently("hg", "identify", repo.url.String()) == nil {
return MercurialBackend, repo.URL()
} else if utils.RunSilently("git", "ls-remote", repo.url.String()) == nil {
} else if cmdutil.RunSilently("git", "ls-remote", repo.url.String()) == nil {
return GitBackend, repo.URL()
} else {
return nil, nil
@ -173,7 +173,7 @@ func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) {
}
// Detect VCS backend automatically
if utils.RunSilently("git", "ls-remote", repo.url.String()) == nil {
if cmdutil.RunSilently("git", "ls-remote", repo.url.String()) == nil {
return GitBackend, repo.URL()
}
@ -183,11 +183,11 @@ func (repo *OtherRepository) VCS() (*VCSBackend, *url.URL) {
return vcsRegistry[vcs], repoURL
}
if utils.RunSilently("hg", "identify", repo.url.String()) == nil {
if cmdutil.RunSilently("hg", "identify", repo.url.String()) == nil {
return MercurialBackend, repo.URL()
}
if utils.RunSilently("svn", "info", repo.url.String()) == nil {
if cmdutil.RunSilently("svn", "info", repo.url.String()) == nil {
return SubversionBackend, repo.URL()
}

View file

@ -4,7 +4,7 @@ import (
"errors"
"net/url"
"github.com/motemen/ghq/utils"
"github.com/motemen/ghq/cmdutil"
. "github.com/onsi/gomega"
)
import "testing"
@ -72,7 +72,7 @@ func TestNewRemoteRepositoryGoogleCode(t *testing.T) {
repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/vim/"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
utils.CommandRunner = NewFakeRunner(map[string]error{
cmdutil.CommandRunner = NewFakeRunner(map[string]error{
"hg identify": nil,
"git ls-remote": errors.New(""),
})
@ -82,7 +82,7 @@ func TestNewRemoteRepositoryGoogleCode(t *testing.T) {
repo, err = NewRemoteRepository(parseURL("https://code.google.com/p/git-core"))
Expect(err).To(BeNil())
Expect(repo.IsValid()).To(Equal(true))
utils.CommandRunner = NewFakeRunner(map[string]error{
cmdutil.CommandRunner = NewFakeRunner(map[string]error{
"hg identify": errors.New(""),
"git ls-remote": nil,
})

28
vcs.go
View file

@ -6,7 +6,7 @@ import (
"os"
"path/filepath"
"github.com/motemen/ghq/utils"
"github.com/motemen/ghq/cmdutil"
)
// A VCSBackend represents a VCS backend.
@ -31,10 +31,10 @@ var GitBackend = &VCSBackend{
}
args = append(args, remote.String(), local)
return utils.Run("git", args...)
return cmdutil.Run("git", args...)
},
Update: func(local string) error {
return utils.RunInDir(local, "git", "pull", "--ff-only")
return cmdutil.RunInDir(local, "git", "pull", "--ff-only")
},
}
@ -52,10 +52,10 @@ var SubversionBackend = &VCSBackend{
}
args = append(args, remote.String(), local)
return utils.Run("svn", args...)
return cmdutil.Run("svn", args...)
},
Update: func(local string) error {
return utils.RunInDir(local, "svn", "update")
return cmdutil.RunInDir(local, "svn", "update")
},
}
@ -68,10 +68,10 @@ var GitsvnBackend = &VCSBackend{
return err
}
return utils.Run("git", "svn", "clone", remote.String(), local)
return cmdutil.Run("git", "svn", "clone", remote.String(), local)
},
Update: func(local string) error {
return utils.RunInDir(local, "git", "svn", "rebase")
return cmdutil.RunInDir(local, "git", "svn", "rebase")
},
}
@ -84,10 +84,10 @@ var MercurialBackend = &VCSBackend{
return err
}
return utils.Run("hg", "clone", remote.String(), local)
return cmdutil.Run("hg", "clone", remote.String(), local)
},
Update: func(local string) error {
return utils.RunInDir(local, "hg", "pull", "--update")
return cmdutil.RunInDir(local, "hg", "pull", "--update")
},
}
@ -105,10 +105,10 @@ var DarcsBackend = &VCSBackend{
}
args = append(args, remote.String(), local)
return utils.Run("darcs", args...)
return cmdutil.Run("darcs", args...)
},
Update: func(local string) error {
return utils.RunInDir(local, "darcs", "pull")
return cmdutil.RunInDir(local, "darcs", "pull")
},
}
@ -131,7 +131,7 @@ var FossilBackend = &VCSBackend{
return err
}
err = utils.Run("fossil", "clone", remote.String(), filepath.Join(dir, fossilRepoName))
err = cmdutil.Run("fossil", "clone", remote.String(), filepath.Join(dir, fossilRepoName))
if err != nil {
return err
}
@ -141,10 +141,10 @@ var FossilBackend = &VCSBackend{
return err
}
return utils.Run("fossile", "open", fossilRepoName)
return cmdutil.Run("fossile", "open", fossilRepoName)
},
Update: func(local string) error {
return utils.RunInDir(local, "fossil", "update")
return cmdutil.RunInDir(local, "fossil", "update")
},
}

View file

@ -7,7 +7,7 @@ import (
"path/filepath"
"testing"
"github.com/motemen/ghq/utils"
"github.com/motemen/ghq/cmdutil"
. "github.com/onsi/gomega"
)
@ -28,7 +28,7 @@ func TestGitBackend(t *testing.T) {
commands := []*exec.Cmd{}
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
utils.CommandRunner = func(cmd *exec.Cmd) error {
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}
@ -76,7 +76,7 @@ func TestSubversionBackend(t *testing.T) {
commands := []*exec.Cmd{}
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
utils.CommandRunner = func(cmd *exec.Cmd) error {
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}
@ -124,7 +124,7 @@ func TestGitsvnBackend(t *testing.T) {
commands := []*exec.Cmd{}
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
utils.CommandRunner = func(cmd *exec.Cmd) error {
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}
@ -171,7 +171,7 @@ func TestMercurialBackend(t *testing.T) {
commands := []*exec.Cmd{}
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
utils.CommandRunner = func(cmd *exec.Cmd) error {
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}
@ -218,7 +218,7 @@ func TestDarcsBackend(t *testing.T) {
commands := []*exec.Cmd{}
lastCommand := func() *exec.Cmd { return commands[len(commands)-1] }
utils.CommandRunner = func(cmd *exec.Cmd) error {
cmdutil.CommandRunner = func(cmd *exec.Cmd) error {
commands = append(commands, cmd)
return nil
}