Skip to content

Commit

Permalink
Merge pull request #59 from tamada/issue/support_rrh_subcommand_execu…
Browse files Browse the repository at this point in the history
…tables

ref #54 supports executing external command.
  • Loading branch information
tamada committed May 22, 2019
2 parents 780f322 + 6c44dfc commit e492216
Show file tree
Hide file tree
Showing 35 changed files with 593 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage.out
rrh
rrh-*
vendor

### https://raw.github.com/github/gitignore/2fa80028c33ad84ff08f993966caa91f0b327fed/Global/Emacs.gitignore
Expand Down
46 changes: 23 additions & 23 deletions Gopkg.lock

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

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
unused-packages = true

[[constraint]]
name = "github.com/ogier/pflag"
version = "0.0.1"
name = "github.com/spf13/pflag"
version = "1.0.3"
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ setup: deps update_version
git submodule update --init

test: setup format lint
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./... | grep -v vendor)
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./...)

build: setup
$(GO) build -o $(NAME) -v
cd cmd/rrh; $(GO) build
cd cmd/rrh-helloworld; $(GO) build

lint: setup
$(GO) vet $$(go list ./... | grep -v vendor)
for pkg in $$(go list ./... | grep -v vendor); do \
$(GO) vet $$(go list ./...)
for pkg in $$(go list ./...); do \
golint -set_exit_status $$pkg || exit $$?; \
done

Expand All @@ -46,12 +47,13 @@ format: setup
# However, goimports could not accept package name 'main'.
# Therefore, we replace 'main' to the go source code name 'rrh.go'
# Other packages are no problem, their have the same name with directories.
goimports -w $$(go list -f '{{.Name}}' ./... | sed 's/main/rrh.go/g')
goimports -w $$(go list ./... | sed 's/github.com\/tamada\/rrh\///g')

install: test build
$(GO) install $(LDFLAGS)
. ./completions/rrh_completion.bash

clean:
$(GO) clean
rm -rf $(NAME)
rm -rf cmd/$(NAME)/$(NAME)
rm -rf cmd/rrh-helloworld/rrh-helloworld
52 changes: 41 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ RRH is now growing. Please hack RRH itself.
Install rrh via [Homebrew](https://brew.sh), simply run:

```sh
$ brew tap tamada/rrh
$ brew tap tamada/brew
$ brew install rrh
```


### Golang

To install cli, simply run:
To install by cli, simply run:

```
```shell
$ go get git@github.com/tamada/rrh.git
```

Expand Down Expand Up @@ -90,25 +89,35 @@ RRH has various subcommands, however, `list` and `add` subcommand make you happy
### Command references

```sh
Usage: rrh [--version] [--help] <command> [<args>]

Available commands are:
rrh [GLOBAL OPTIONS] <SUB COMMANDS> [ARGUMENTS]
GLOBAL OPTIONS
-h, --help print this message.
-v, --version print version.
-c, --config-file <CONFIG_FILE> specifies the config file path.
AVAILABLE SUB COMMANDS:
add add repositories on the local path to RRH.
clone run "git clone" and register it to a group.
config set/unset and list configuration of RRH.
export export RRH database to stdout.
fetch run "git fetch" on the repositories of the given groups.
fetch run "git fetch" on the given groups.
fetch-all run "git fetch" in the all repositories.
group add/list/update/remove groups.
group add/list/update/remove groups and show groups of the repository.
help print this message.
import import the given database.
list print managed repositories and their groups.
mv move the repositories from groups to another group.
path print paths of specified repositories.
prune prune unnecessary repositories and groups.
repository manages repository.
repository manages repositories.
rm remove given repository from database.
status show git status of repositories.
version show version.
```

If the user specified an unknown subcommand (e.g., `rrh helloworld`), `rrh` treats it as an **external command**.
In that case, `rrh` searches an executable file named `rrh-helloworld` from the PATH environment variable.
If `rrh` found it, `rrh` executes it, if not found, `rrh` prints help and exit.

### Subcommands

#### `rrh add`
Expand Down Expand Up @@ -273,6 +282,16 @@ ARGUMENTS
GROUP update target group names.
```
#### `rrh help`
Prints the help message.
```shell
rrh help [ARGUMENTS...]
ARGUMENTS
print help message of target command.
```
#### `rrh import`
Import the database to the local environment.
Expand Down Expand Up @@ -420,6 +439,15 @@ ARGUMENTS
shows the result of default group.
```
#### `rrh version`
Prints `rrh` version.
```sh
rrh version
```
### Environment variables
We can see those variables by running `rrh config` sub-command.
Expand Down Expand Up @@ -623,7 +651,7 @@ rrhpeco(){
[![Gitter](https://img.shields.io/badge/Gitter-Join_Chat-red.svg)](https://gitter.im/rrh_git/community)
[![Gitter misc_ja](https://img.shields.io/badge/Gitter-For_Japanese-red.svg)](https://gitter.im/rrh_git/misc_ja)
Join our Gitter channel if you have any problem or suggestions to Rrh.
Join our Gitter channel if you have any problem or suggestions to `rrh`.
For Japanese user, `misc_ja` channel has discussions in Japanese.
The public language of other channels and GitHub pages are English.
Expand Down Expand Up @@ -657,6 +685,7 @@ RRH means "Repositories, Ready to Hack," is not the abbreviation of the Red Ridi
* [`rrh fetch`](#rrh-fetch)
* [`rrh fetch-all`](#rrh-fetch-all)
* [`rrh group`](#rrh-group)
* [`rrh help`](#rrh-help)
* [`rrh import`](#rrh-import)
* [`rrh list`](#rrh-list)
* [`rrh mv`](#rrh-mv)
Expand All @@ -665,6 +694,7 @@ RRH means "Repositories, Ready to Hack," is not the abbreviation of the Red Ridi
* [`rrh repository`](#rrh-repository)
* [`rrh rm`](#rrh-rm)
* [`rrh status`](#rrh-status)
* [`rrh version`](#rrh-version)
* [Environment variables](#environment-variables)
* [Development](#development)
* [Database](#database)
Expand Down
11 changes: 6 additions & 5 deletions add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ func findID(repoID string, absPath string) string {
return repoID
}

func (add *Command) addRepositoryToGroup(db *common.Database, repoID string, groupName string, path string) []error {
// func (add *Command) addRepositoryToGroup(db *common.Database, repoID string, groupName string, path string) []error {
func (add *Command) addRepositoryToGroup(db *common.Database, rel common.Relation, path string) []error {
var absPath, _ = filepath.Abs(path)
var id = findID(repoID, absPath)
var id = findID(rel.RepositoryID, absPath)
if err1 := common.IsExistAndGitRepository(absPath, path); err1 != nil {
return []error{err1}
}
Expand All @@ -38,9 +39,9 @@ func (add *Command) addRepositoryToGroup(db *common.Database, repoID string, gro
}
db.CreateRepository(id, absPath, "", remotes)

var err = db.Relate(groupName, id)
var err = db.Relate(rel.GroupName, id)
if err != nil {
return []error{fmt.Errorf("%s: cannot create relation to group %s", id, groupName)}
return []error{fmt.Errorf("%s: cannot create relation to group %s", id, rel.GroupName)}
}
return []error{}
}
Expand All @@ -65,7 +66,7 @@ func (add *Command) AddRepositoriesToGroup(db *common.Database, opt *options) []
}
var errorlist = []error{}
for _, item := range opt.args {
var list = add.addRepositoryToGroup(db, opt.repoID, opt.group, item)
var list = add.addRepositoryToGroup(db, common.Relation{RepositoryID: opt.repoID, GroupName: opt.group}, item)
errorlist = append(errorlist, list...)
}
return errorlist
Expand Down
9 changes: 4 additions & 5 deletions add/add_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/mitchellh/cli"
flag "github.com/ogier/pflag"
flag "github.com/spf13/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 @@ -70,7 +70,6 @@ func (add *Command) Run(args []string) int {
var opt, err = add.parse(args, config)
if err != nil {
fmt.Println(err.Error())
fmt.Println(add.Help())
return 1
}
var db, err2 = common.Open(config)
Expand Down Expand Up @@ -112,5 +111,5 @@ func (add *Command) parse(args []string, config *common.Config) (*options, error
Synopsis returns the simple help message of the command.
*/
func (add *Command) Synopsis() string {
return "add repositories on the local path to RRH."
return "add repositories on the local path to rrh."
}
Loading

0 comments on commit e492216

Please sign in to comment.