Skip to content

Commit

Permalink
Merge pull request #84 from tamada/introduce_open_subcommand
Browse files Browse the repository at this point in the history
ref #83 implement rrh-open command.
  • Loading branch information
tamada committed Apr 22, 2020
2 parents f9b9a4a + 52c0840 commit 9796901
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 94 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ setup: deps update_version
test: setup
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./...)

define _buildSubcommand
$(GO) build -o rrh-$(1) cmd/rrh-$(1)/*.go
endef

build: setup
$(GO) build
cd cmd/rrh-helloworld; $(GO) build
@$(call _buildSubcommand,helloworld)
@$(call _buildSubcommand,new)

lint: setup format
$(GO) vet $$(go list ./...)
Expand All @@ -47,5 +52,4 @@ install: test build

clean:
$(GO) clean
rm -rf cmd/$(NAME)/$(NAME)
rm -rf cmd/rrh-helloworld/rrh-helloworld
rm -rf rrh rrh-helloworld rrh-new
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ AVAILABLE SUB COMMANDS:
import import the given database.
list print managed repositories and their groups.
mv move the repositories from groups to another group.
open open folder or web page of the given repositories.
prune prune unnecessary repositories and groups.
repository manages repositories.
rm remove given repository from database.
Expand Down Expand Up @@ -344,6 +345,20 @@ ARGUMENTS
TO specifies move to, formatted in <GROUP_NAME>
```
#### `rrh open`
Opens folder or web page of the given repositories.
```sh
rrh open [OPTIONS] <REPOSITORIES...>
OPTIONS
-f, --folder open the folder of the specified repository (Default).
-w, --webpage open the webpage of the specified repository.
-h, --help print this message.
ARGUMENTS
REPOSITORIES specifies repository names.
```
#### `rrh prune`
Deletes unnecessary groups and repositories.
Expand Down
43 changes: 23 additions & 20 deletions cmd/rrh-new/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import (
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)

type newOptions struct {
type repositoryInfo struct {
description string
group string
homepage string
parentPath string
privateFlag bool
dryrunMode bool
helpFlag bool
}

type newOptions struct {
group string
parentPath string
info *repositoryInfo
dryrunMode bool
helpFlag bool
}

func getHelpMessage() string {
Expand All @@ -37,44 +41,43 @@ OPTIONS
-h, --help print this message.
ARGUMENTS
ORGANIZATION specifies organization, if needed.
REPOSITORY specifies repository name, and it is directory name.
`
REPOSITORY specifies repository name, and it is directory name.`
}

func buildFlagSet(config *lib.Config) (*flag.FlagSet, *newOptions) {
var opt = newOptions{}
var opt = newOptions{info: new(repositoryInfo)}
var defaultGroup = config.GetValue(lib.RrhDefaultGroupName)
flags := flag.NewFlagSet("new", flag.ContinueOnError)
flags.Usage = func() { fmt.Println(getHelpMessage()) }
flags.StringVarP(&opt.description, "description", "d", "", "specifys description of the project")
flags.StringVarP(&opt.info.description, "description", "d", "", "specifys description of the project")
flags.StringVarP(&opt.group, "group", "g", defaultGroup, "target group")
flags.StringVarP(&opt.homepage, "homepage", "H", "", "specifies homepage url")
flags.StringVarP(&opt.info.homepage, "homepage", "H", "", "specifies homepage url")
flags.StringVarP(&opt.parentPath, "parent-path", "P", ".", "specifies the destination path")
flags.BoolVarP(&opt.privateFlag, "private", "p", false, "create a private repository")
flags.BoolVarP(&opt.info.privateFlag, "private", "p", false, "create a private repository")
flags.BoolVarP(&opt.dryrunMode, "dry-run", "D", false, "performs on dry run mode")
flags.BoolVarP(&opt.helpFlag, "help", "h", false, "print this message")
return flags, &opt
}

func createArgsToHubCommand(projectName string, opts *newOptions) []string {
func createArgsToHubCommand(projectName string, info *repositoryInfo) []string {
var args = []string{"create"}
if opts.homepage != "" {
if info.homepage != "" {
args = append(args, "--homepage")
args = append(args, opts.homepage)
args = append(args, info.homepage)
}
if opts.privateFlag {
if info.privateFlag {
args = append(args, "--private")
}
if opts.description != "" {
if info.description != "" {
args = append(args, "--description")
args = append(args, opts.description)
args = append(args, info.description)
}
args = append(args, projectName)
return args
}

func createProjectPage(repo *repo, opts *newOptions) (string, error) {
var argsToHub = createArgsToHubCommand(repo.givenString, opts)
var argsToHub = createArgsToHubCommand(repo.givenString, opts.info)
var cmdString = "hub " + strings.Join(argsToHub, " ")
if opts.dryrunMode {
return cmdString, nil
Expand Down Expand Up @@ -169,7 +172,7 @@ func registerToGroup(db *lib.Database, repo *repo, opts *newOptions) error {
return nil
}
var remotes, _ = lib.FindRemotes(repo.dest)
var _, err1 = db.CreateRepository(repo.repoName, repo.dest, opts.description, remotes)
var _, err1 = db.CreateRepository(repo.repoName, repo.dest, opts.info.description, remotes)
if err1 != nil {
return err1
}
Expand Down Expand Up @@ -234,7 +237,7 @@ func perform(config *lib.Config, args []string, opts *newOptions) int {
return 0
}
var errs = createRepositories(config, args, opts)
return config.PrintErrors(errs)
return config.PrintErrors(errs...)
}

func goMain(args []string) int {
Expand Down
15 changes: 14 additions & 1 deletion completions/bash/rrh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ __rrh_new() {
fi
}

__rrh_open() {
if [[ "$1" =~ ^\- ]]; then
COMPREPLY=($(compgen -W "-f --folder -w --webpage -h --help" -- "${cur}"))
else
repositories="$(__rrh_repository)"
COMPREPLY=($(compgen -W "$repositories" -- "${cur}"))
fi
}

__rrh_path() {
if [[ "$1" =~ ^\- ]]; then
COMPREPLY=($(compgen -W "-m --partial-match -p --show-only-path" -- "${cur}"))
Expand Down Expand Up @@ -305,7 +314,7 @@ __rrh_completions()
subcom=${COMP_WORDS[$subcomIndex]}
fi
# echo "cur: $cur, prev: $prev, cword: $cword, subcom: $subcom, index: $subcomIndex"
opts="add clone config export fetch fetch-all group help import list mv new prune repository rm status version"
opts="add clone config export fetch fetch-all group help import list mv new open prune repository rm status version"

case "${subcom}" in
add)
Expand Down Expand Up @@ -359,6 +368,10 @@ __rrh_completions()
prune)
return 0
;;
open)
__rrh_open "$cur" "$prev" "$cword" "$subcom" $subcomIndex
return 0
;;
repository)
__rrh_repository "$cur" "$prev" "$cword" "$subcom" $subcomIndex
return 0
Expand Down
16 changes: 8 additions & 8 deletions docs/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "http://tamada.github.io/rrh"
baseURL = "https://tamada.github.io/rrh"
languageCode = "en-us"
defaultContentLanguage = "en"
title = "rrh"
Expand All @@ -19,30 +19,30 @@ pygmentsStyle = "pygments"

[menu]
[[menu.nav]]
name = "Home"
name = ":house: Home"
url = "/"
weight = 1
[[menu.nav]]
name = "Description"
name = ":bookmark_tabs: Description"
url = "/description/"
weight = 2
[[menu.nav]]
name = "Installation"
name = ":anchor: Installation"
url = "/installation/"
weight = 3
[[menu.nav]]
name = "Usage"
name = ":fork_and_knife: Usage"
url = "/usage/"
weight = 4
[[menu.nav]]
name = "Development"
name = ":pencil2: Development"
url = "/development/"
weight = 5
[[menu.nav]]
name = "Utilities"
name = ":electric_plug: Utilities"
url = "/utilities/"
weight = 6
[[menu.nav]]
name = "About"
name = ":smile: About"
url = "/about/"
weight = 7
35 changes: 18 additions & 17 deletions docs/content/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: RRH
title: ":house: RRH"
---

[![Build Status](https://travis-ci.org/tamada/rrh.svg?branch=master)](https://travis-ci.org/tamada/rrh)
Expand All @@ -13,27 +13,28 @@ RRH is a simple git repository manager.

## Table of Contents

* [Description](description)
* [Installation](installation)
* [Homebrew](installation#homebrew)
* [:bookmark_tabs: Description](description)
* [:anchor: Installation](installation)
* [:beer: Homebrew](installation#beer-homebrew)
* [Golang](installation#golang)
* [Requirements](installation#requirements)
* [Usage](usage)
* [:hammer_and_wrench: Build form source codes](installation#hammer_and_wrench-build-from-source-codes)
* [:white_check_mark: Requirements](installation#white_check_mark-requirements)
* [:fork_and_knife: Usage](usage)
* [Getting Started](usage#getting-started)
* [Command references](usage#command-references)
* [Subcommands](usage#subcommands)
* [Environment Variables](usage#environment-variables)
* [Development](development)
* [:pencil2: Development](development)
* [Database](development#database)
* [Utilities](utilities)
* [:electric_plug: Utilities](utilities)
* [`cdrrh`](utilities#cdrrh)
* [`rrhpeco`](utilities#rrhpeco)
* [About the Project](about)
* [Contribution](about#contribution)
* [Code of Conduct](about#code-of-conduct)
* [License](about#license)
* [Discussion](about#disucussion)
* [Authors](about#authors)
* [Why the project name RRH](about#why-the-project-name-rrh)
* [Attributions](about#attributions)
* [Version histories](about#version-histories)
* [:smile: About the Project](about)
* [:raised_hand: Contribution](about#raised_hand-contribution)
* [:green_book: Code of Conduct](about#green_book-code-of-conduct)
* [:scroll: License](about#scroll-license)
* [:speech_balloon: Discussion](about#speech_balloon-discussion)
* [:busts_in_silhouette: Authors](about#busts_in_silhouette-authors)
* [:question: Why the project name RRH](about#question-why-the-project-name-rrh)
* [:handshake: Attributions](about#handshake-attributions)
* [:paw_prints: Version histories](about#paw_prints-version-histories)
20 changes: 10 additions & 10 deletions docs/content/about.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: About the Project
title: ":smile: About the Project"
---

[![Contribution](https://img.shields.io/badge/RRH-Contribution-yellow.svg)](https://github.com/tamada/rrh/blob/master/CONTRIBUTION.md)
Expand All @@ -9,7 +9,7 @@ title: About the Project
[![Gitter misc_ja](https://img.shields.io/badge/Gitter-For_Japanese-red.svg)](https://gitter.im/rrh_git/misc_ja)


### Contribution
## :raised_hand: Contribution

1. Fork the project. ([https://github.com/tamada/rrh/fork](https://github.com/tamada/rrh/fork))
2. Create a feature branch. (`git checkout -b FEATURE_BRANCH_NAME`)
Expand All @@ -23,17 +23,17 @@ title: About the Project
[![Contribution](https://img.shields.io/badge/RRH-Contribution-yellow.svg)](https://github.com/tamada/rrh/blob/master/CONTRIBUTION.md)


### Code of Conduct
## :green_book: Code of Conduct

[![Code of Conduct](https://img.shields.io/badge/RRH-Code_of_Conduct-orange.svg)](https://github.com/tamada/rrh/blob/master/CODE_OF_CONDUCT.md)

### License
## :scroll: License

[Apache License version 2.0](https://github.com/tamada/rrh/blob/master/LICENSE)

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/tamada/rrh/blob/master/LICENSE)

### Discussion
## :speech_balloon: Discussion

[![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)
Expand All @@ -43,24 +43,24 @@ 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 project pages are English.

### Authors
## :busts_in_silhouette: Authors

{{< githubuser tamada >}}

### Why the project name RRH
## :question: Why the project name RRH

At first, the name of this project was GRIM (Git Repository Integrated Manager).
However, the means of `grim` is not good, and there are many commands which start with `gr`.
Therefore, we changed the project name to `rrh`.
RRH means "Repositories, Ready to Hack" or "Remote Repositories Head," are not the abbreviation of the Red Riding Hood.

### Attributions
## :handshake: Attributions

#### Icon of RRH
### Icon of RRH

{{< figure src="/rrh/images/logo.png" width="64" >}} by [iconpon.com](https://www.iconpon.com/)

### Version histories
## :paw_prints: Version histories

* [v1.1.0](https://github.com/tamada/rrh/releases/tag/v1.1.0) (18 Dec, 2018)
* [\#79](https://github.com/tamada/rrh/issues/79) (add `rrh group info` sub command)
Expand Down
2 changes: 1 addition & 1 deletion docs/content/description.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Description
title: ":bookmark_tabs: Description"
---

There are too many repositories.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/development.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Development
title: ":pencil2: Development"
---

### Database
## Database

The database for managed repositories is formatted in JSON.
The JSON format is as follows.
Expand Down

0 comments on commit 9796901

Please sign in to comment.