Skip to content

Commit

Permalink
Merge 3c5de29 into 2ac4a93
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed May 20, 2019
2 parents 2ac4a93 + 3c5de29 commit bf79b37
Show file tree
Hide file tree
Showing 27 changed files with 228 additions and 208 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "testdata/helloworld2"]
path = testdata/other/helloworld
url = https://htamada@bitbucket.org/htamada/helloworld2.git
[submodule "docs/themes/hugo-theme-massively"]
path = docs/themes/hugo-theme-massively
url = https://github.com/curtistimson/hugo-theme-massively.git
[submodule "docs/themes/cayman-hugo-theme"]
path = docs/themes/cayman-hugo-theme
url = https://github.com/zwbetz-gh/cayman-hugo-theme.git
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/ogier/pflag"
version = "0.0.1"
4 changes: 2 additions & 2 deletions add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (add *Command) AddRepositoriesToGroup(db *common.Database, opt *options) []
FindRemotes function returns the remote of the given git repository.
*/
func FindRemotes(path string) ([]common.Remote, error) {
r, err := git.PlainOpen(path)
var repo, err = git.PlainOpen(path)
if err != nil {
return nil, err
}
remotes, err := r.Remotes()
remotes, err := repo.Remotes()
if err != nil {
return nil, err
}
Expand Down
12 changes: 5 additions & 7 deletions add/add_cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package add

import (
"flag"
"fmt"

"github.com/mitchellh/cli"
flag "github.com/ogier/pflag"
"github.com/tamada/rrh/common"
)

Expand All @@ -28,8 +28,8 @@ Help function shows the help message.
func (add *Command) Help() string {
return `rrh add [OPTIONS] <REPOSITORY_PATHS...>
OPTIONS
-g, --group <GROUP> add repository to RRH database.
-r, --repository-id <ID> specified repository id of the given repository path.
-g, --group=<GROUP> add repository to RRH database.
-r, --repository-id=<ID> specified repository id of the given repository path.
Specifying this option fails with multiple arguments.
ARGUMENTS
REPOSITORY_PATHS the local path list of the git repositories.`
Expand Down Expand Up @@ -92,10 +92,8 @@ func (add *Command) buildFlagSet(config *common.Config) (*flag.FlagSet, *options
var defaultGroup = config.GetValue(common.RrhDefaultGroupName)
flags := flag.NewFlagSet("add", flag.ContinueOnError)
flags.Usage = func() { fmt.Println(add.Help()) }
flags.StringVar(&opt.group, "g", defaultGroup, "target group")
flags.StringVar(&opt.group, "group", defaultGroup, "target group")
flags.StringVar(&opt.repoID, "r", "", "specifying repository id")
flags.StringVar(&opt.repoID, "repository-id", "", "specifying repository id")
flags.StringVarP(&opt.group, "group", "g", defaultGroup, "target group")
flags.StringVarP(&opt.repoID, "repository-id", "r", "", "specifying repository id")
return flags, &opt
}

Expand Down
29 changes: 24 additions & 5 deletions add/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func TestHelpAndSynopsis(t *testing.T) {
}
if command.Help() != `rrh add [OPTIONS] <REPOSITORY_PATHS...>
OPTIONS
-g, --group <GROUP> add repository to RRH database.
-r, --repository-id <ID> specified repository id of the given repository path.
-g, --group=<GROUP> add repository to RRH database.
-r, --repository-id=<ID> specified repository id of the given repository path.
Specifying this option fails with multiple arguments.
ARGUMENTS
REPOSITORY_PATHS the local path list of the git repositories.` {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestAdd(t *testing.T) {
rCheckers []repositoryChecker
relCheckers []relationChecker
}{
{[]string{"--group", "group2", "../testdata/helloworld"}, 0,
{[]string{"--group=group2", "../testdata/helloworld"}, 0,
[]groupChecker{{"group2", true}},
[]repositoryChecker{{"helloworld", true}},
[]relationChecker{{"group2", "helloworld", true}},
Expand All @@ -74,12 +74,12 @@ func TestAdd(t *testing.T) {
[]repositoryChecker{{"helloworld", true}},
[]relationChecker{{"no-group", "helloworld", true}},
},
{[]string{"--repository-id", "hw", "../testdata/other/helloworld"}, 0,
{[]string{"--repository-id=hw", "../testdata/other/helloworld"}, 0,
[]groupChecker{},
[]repositoryChecker{{"hw", true}},
[]relationChecker{{"no-group", "hw", true}},
},
{[]string{"--repository-id", "fails", "../testdata/other/helloworld", "../testdata/fibonacci"}, 0,
{[]string{"--repository-id=fails", "../testdata/other/helloworld", "../testdata/fibonacci"}, 0,
[]groupChecker{},
[]repositoryChecker{},
[]relationChecker{},
Expand Down Expand Up @@ -164,3 +164,22 @@ func TestAddFailed(t *testing.T) {
}
}
}

func TestFindRemotes(t *testing.T) {
var testdata = []struct {
path string
errorFlag bool
count int
}{
{"../testdata/dummygit", true, 0},
}
for _, td := range testdata {
var remotes, err = FindRemotes(td.path)
if (err == nil) == td.errorFlag {
t.Errorf("%s: error flag did not match, wont: %v, got: %v, %v", td.path, td.errorFlag, !td.errorFlag, err)
}
if err != nil && td.count != len(remotes) {
t.Errorf("%s: remote count did not match, wont: %d, got: %d", td.path, td.count, len(remotes))
}
}
}
15 changes: 6 additions & 9 deletions clone/clone_cmd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package clone

import (
"flag"
"fmt"

"github.com/mitchellh/cli"
flag "github.com/ogier/pflag"
"github.com/tamada/rrh/common"
)

Expand Down Expand Up @@ -34,8 +34,8 @@ Help function shows the help message.
func (clone *Command) Help() string {
return `rrh clone [OPTIONS] <REMOTE_REPOS...>
OPTIONS
-g, --group <GROUP> print managed repositories categorized in the group.
-d, --dest <DEST> specify the destination.
-g, --group=<GROUP> print managed repositories categorized in the group.
-d, --dest=<DEST> specify the destination.
-v, --verbose verbose mode.
ARGUMENTS
REMOTE_REPOS repository urls`
Expand Down Expand Up @@ -109,12 +109,9 @@ func (clone *Command) buildFlagSets(config *common.Config) (*flag.FlagSet, *opti
var options = options{defaultGroup, ".", false}
flags := flag.NewFlagSet("clone", flag.ContinueOnError)
flags.Usage = func() { fmt.Println(clone.Help()) }
flags.StringVar(&options.group, "g", defaultGroup, "belonging group")
flags.StringVar(&options.group, "group", defaultGroup, "belonging group")
flags.StringVar(&options.dest, "d", destination, "destination")
flags.StringVar(&options.dest, "dest", destination, "destination")
flags.BoolVar(&options.verbose, "v", false, "verbose mode")
flags.BoolVar(&options.verbose, "verbose", false, "verbose mode")
flags.StringVarP(&options.group, "group", "g", defaultGroup, "belonging group")
flags.StringVarP(&options.dest, "dest", "d", destination, "destination")
flags.BoolVarP(&options.verbose, "verbose", "v", false, "verbose mode")
return flags, &options
}

Expand Down
6 changes: 3 additions & 3 deletions clone/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestCommand_Run(t *testing.T) {
func TestCommand_SpecifyingId(t *testing.T) {
var dbFile = common.Rollback("../testdata/tmp.json", "../testdata/config.json", func() {
var clone, _ = CommandFactory()
clone.Run([]string{"-d", "../testdata/newid", "../testdata/helloworld"})
clone.Run([]string{"--dest=../testdata/newid", "../testdata/helloworld"})
defer cleanup([]string{"../testdata/newid"})

var config = common.OpenConfig()
Expand Down Expand Up @@ -143,8 +143,8 @@ func TestCloneNotGitRepository(t *testing.T) {
func TestHelpAndSynopsis(t *testing.T) {
var helpMessage = `rrh clone [OPTIONS] <REMOTE_REPOS...>
OPTIONS
-g, --group <GROUP> print managed repositories categorized in the group.
-d, --dest <DEST> specify the destination.
-g, --group=<GROUP> print managed repositories categorized in the group.
-d, --dest=<DEST> specify the destination.
-v, --verbose verbose mode.
ARGUMENTS
REMOTE_REPOS repository urls`
Expand Down
8 changes: 2 additions & 6 deletions common/config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"fmt"
"log"

"github.com/mitchellh/cli"
)
Expand Down Expand Up @@ -87,10 +86,7 @@ func (config *Command) Run(args []string) int {
new(listCommand).Run([]string{})
return 0
}
var exitStatus, err = c.Run()
if err != nil {
log.Println(err)
}
var exitStatus, _ = c.Run()
return exitStatus
}

Expand All @@ -106,7 +102,7 @@ func (csc *setCommand) Run(args []string) int {
var err = config.Update(args[0], args[1])
if err != nil {
fmt.Println(err.Error())
return 1
return 2
}
config.StoreConfig()
return 0
Expand Down

0 comments on commit bf79b37

Please sign in to comment.