Skip to content

Commit

Permalink
Merge pull request #87 from tamada/reorganize_layouts
Browse files Browse the repository at this point in the history
Reorganize layouts
  • Loading branch information
tamada committed Apr 24, 2020
2 parents 9796901 + 9eec87a commit 3e24b0a
Show file tree
Hide file tree
Showing 58 changed files with 690 additions and 646 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build
on:
push:
branches:
- "**"
env:
TZ: 'Asia/Tokyo'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
steps:
- name: setup go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: checkout
uses: actions/checkout@v1
- name: build
run: make
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.0
with:
infile: coverage.out
outfile: coverage.lcov
if: "matrix.os == 'ubuntu-latest'"
- name: coveralls
uses: coverallsapp/github-action@v1.0.1
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
if: "matrix.os == 'ubuntu-latest'"
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

44 changes: 32 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
GO=go
SHELL=/bin/bash
NAME := rrh
VERSION := 1.1.0
REVISION := $(shell git rev-parse --short HEAD)
VERSION := 1.2.0
DIST := $(NAME)-$(VERSION)

all: test build

Expand All @@ -12,8 +13,8 @@ update_version:
sed -e 's!Version-[0-9.]*-yellowgreen!Version-${VERSION}-yellowgreen!g' -e 's!tag/v[0-9.]*!tag/v${VERSION}!g' $$i > a ; mv a $$i; \
done

@sed 's/const VERSION = .*/const VERSION = "${VERSION}"/g' lib/config.go > a
@mv a lib/config.go
@sed 's/const VERSION = .*/const VERSION = "${VERSION}"/g' config.go > a
@mv a config.go
@sed 's/ \/\/ rrh version .*/ \/\/ rrh version ${VERSION}/g' internal/messages_test.go > a
@mv a internal/messages_test.go
@echo "Replace version to \"${VERSION}\""
Expand All @@ -25,13 +26,36 @@ test: setup
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./...)

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

build: setup
$(GO) build
@$(call _buildSubcommand,helloworld)
@$(call _buildSubcommand,new)
@$(call _buildSubcommand,rrh)
@$(call _buildSubcommand,rrh-helloworld)
@$(call _buildSubcommand,rrh-new)


# refer from https://pod.hatenablog.com/entry/2017/06/13/150342
define _createDist
echo -n "create dist/$(DIST)_$(1)_$(2).tar.gz ...."
mkdir -p dist/$(1)_$(2)/$(DIST)/bin
GOOS=$1 GOARCH=$2 go build -o dist/$(1)_$(2)/$(DIST)/bin/$(NAME)$(3) cmd/$(NAME)/*.go
GOOS=$1 GOARCH=$2 go build -o dist/$(1)_$(2)/$(DIST)/bin/rrh-helloworld$(3) cmd/rrh-helloworld/*.go
GOOS=$1 GOARCH=$2 go build -o dist/$(1)_$(2)/$(DIST)/bin/rrh-new$(3) cmd/rrh-new/*.go
cp -r completions dist/$(1)_$(2)/$(DIST)
cp -r README.md LICENSE CODE_OF_CONDUCT.md CONTRIBUTING.md dist/$(1)_$(2)/$(DIST)
tar cfz dist/$(DIST)_$(1)_$(2).tar.gz -C dist/$(1)_$(2) $(DIST)
echo "done."
endef

dist: build
@$(call _createDist,darwin,amd64,)
@$(call _createDist,darwin,386,)
@$(call _createDist,windows,amd64,.exe)
@$(call _createDist,windows,386,.exe)
@$(call _createDist,linux,amd64,)
@$(call _createDist,linux,386,)

lint: setup format
$(GO) vet $$(go list ./...)
Expand All @@ -46,10 +70,6 @@ format: setup
# Other packages are no problem, their have the same name with directories.
goimports -w $$(go list ./... | sed 's/github.com\/tamada\/rrh//g' | sed 's/^\///g')

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

clean:
$(GO) clean
rm -rf rrh rrh-helloworld rrh-new
rm -rf rrh rrh-helloworld rrh-new dist
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![Build Status](https://travis-ci.com/tamada/rrh.svg?branch=master)](https://travis-ci.com/tamada/rrh)
[![Build Status](https://github.com/tamada/rrh/workflows/build/badge.svg?branch=master)](https://github.com/tamada/rrh/actions?workflow=build)
[![Coverage Status](https://coveralls.io/repos/github/tamada/rrh/badge.svg?branch=master)](https://coveralls.io/github/tamada/rrh?branch=master)
[![codebeat badge](https://codebeat.co/badges/15e04551-d448-4ad3-be1d-e98b1e586f1a)](https://codebeat.co/projects/github-com-tamada-rrh-master)
[![go report](https://goreportcard.com/badge/github.com/tamada/rrh)](https://goreportcard.com/report/github.com/tamada/rrh)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/tamada/rrh/blob/master/LICENSE)
[![Version](https://img.shields.io/badge/Version-1.1.0-yellowgreen.svg)](https://github.com/tamada/rrh/releases/tag/v1.1.0)
[![Version](https://img.shields.io/badge/Version-1.2.0-yellowgreen.svg)](https://github.com/tamada/rrh/releases/tag/v1.2.0)

# RRH

Expand Down Expand Up @@ -691,20 +691,20 @@ RRH means "Repositories, Ready to Hack" or "Remote Repositories Head," are not t
### Version histories
* [v1.1.0](https://github.com/tamada/rrh/releases/tag/v1.1.0) (18 Dec, 2018)
* [v1.1.0](https://github.com/tamada/rrh/releases/tag/v1.2.0) (18 Dec, 2018)
* [\#79](https://github.com/tamada/rrh/issues/79) (add `rrh group info` sub command)
* [\#77](https://github.com/tamada/rrh/issues/77) (introduce `rrh repository update-remotes` sub command)
* [\#81](https://github.com/tamada/rrh/issues/81) (introduce options for `rrh prune` command)
* [v1.0.4](https://github.com/tamada/rrh/releases/tag/v1.1.0) (13 Jul, 2018)
* [v1.0.4](https://github.com/tamada/rrh/releases/tag/v1.2.0) (13 Jul, 2018)
* [\#74](https://github.com/tamada/rrh/issues/74) (permission of created README.md by rrh-new was invalid (204))
* [\#75](https://github.com/tamada/rrh/issues/75) (Introduce `--dry-run` option to `rrh new` command)
* [v1.0.3](https://github.com/tamada/rrh/releases/tag/v1.1.0) (29 Jun, 2018)
* [v1.0.3](https://github.com/tamada/rrh/releases/tag/v1.2.0) (29 Jun, 2018)
* [\#72](https://github.com/tamada/rrh/issues/72) (Print belonging groups on `rrh repository info`)
* [v1.0.2](https://github.com/tamada/rrh/releases/tag/v1.1.0) (29 Jun, 2018)
* [v1.0.2](https://github.com/tamada/rrh/releases/tag/v1.2.0) (29 Jun, 2018)
* [\#67](https://github.com/tamada/rrh/issues/67) (implements `rrh new` sub command)
* [v1.0.1](https://github.com/tamada/rrh/releases/tag/v1.1.0) (26 Jun, 2018)
* [v1.0.1](https://github.com/tamada/rrh/releases/tag/v1.2.0) (26 Jun, 2018)
* [\#68](https://github.com/tamada/rrh/issues/68) (`rrh group` prints `rrh config list`)
* [v1.0.0](https://github.com/tamada/rrh/releases/tag/v1.1.0) (18 Jun, 2018)
* [v1.0.0](https://github.com/tamada/rrh/releases/tag/v1.2.0) (18 Jun, 2018)
* The first public release.
## Table of Contents
Expand Down
34 changes: 17 additions & 17 deletions cmd/rrh-new/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

flag "github.com/spf13/pflag"
"github.com/tamada/rrh/lib"
"github.com/tamada/rrh"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
Expand Down Expand Up @@ -44,9 +44,9 @@ ARGUMENTS
REPOSITORY specifies repository name, and it is directory name.`
}

func buildFlagSet(config *lib.Config) (*flag.FlagSet, *newOptions) {
func buildFlagSet(config *rrh.Config) (*flag.FlagSet, *newOptions) {
var opt = newOptions{info: new(repositoryInfo)}
var defaultGroup = config.GetValue(lib.RrhDefaultGroupName)
var defaultGroup = config.GetValue(rrh.DefaultGroupName)
flags := flag.NewFlagSet("new", flag.ContinueOnError)
flags.Usage = func() { fmt.Println(getHelpMessage()) }
flags.StringVarP(&opt.info.description, "description", "d", "", "specifys description of the project")
Expand Down Expand Up @@ -100,7 +100,7 @@ func createReadme(dest, projectName string) {
}
}

func makeGitDirectory(config *lib.Config, repo *repo, opts *newOptions) error {
func makeGitDirectory(config *rrh.Config, repo *repo, opts *newOptions) error {
if opts.dryrunMode {
return nil
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func findRepoName(arg string) string {
return terms[1]
}

func createRepo(config *lib.Config, arg string, opts *newOptions) (*repo, error) {
func createRepo(config *rrh.Config, arg string, opts *newOptions) (*repo, error) {
var dest, err = findDirectoryName(arg, opts)
if err != nil {
return nil, err
Expand All @@ -167,11 +167,11 @@ func createRepo(config *lib.Config, arg string, opts *newOptions) (*repo, error)
return &repo{givenString: arg, dest: dest, repoName: repoName}, nil
}

func registerToGroup(db *lib.Database, repo *repo, opts *newOptions) error {
func registerToGroup(db *rrh.Database, repo *repo, opts *newOptions) error {
if opts.dryrunMode {
return nil
}
var remotes, _ = lib.FindRemotes(repo.dest)
var remotes, _ = rrh.FindRemotes(repo.dest)
var _, err1 = db.CreateRepository(repo.repoName, repo.dest, opts.info.description, remotes)
if err1 != nil {
return err1
Expand All @@ -183,7 +183,7 @@ func registerToGroup(db *lib.Database, repo *repo, opts *newOptions) error {
return nil
}

func createRepository(db *lib.Database, arg string, opts *newOptions) error {
func createRepository(db *rrh.Database, arg string, opts *newOptions) error {
var repo, err = createRepo(db.Config, arg, opts)
if err == nil {
err = makeGitDirectory(db.Config, repo, opts)
Expand All @@ -201,28 +201,28 @@ func createRepository(db *lib.Database, arg string, opts *newOptions) error {
return err
}

func isOnError(config *lib.Config, handler string) bool {
var onError = config.GetValue(lib.RrhOnError)
func isOnError(config *rrh.Config, handler string) bool {
var onError = config.GetValue(rrh.OnError)
return onError == handler
}

func storeDbWhenSucceeded(db *lib.Database, errors []error) {
func storeDbWhenSucceeded(db *rrh.Database, errors []error) {
var config = db.Config
if len(errors) == 0 || isOnError(config, lib.Ignore) {
if len(errors) == 0 || isOnError(config, rrh.Ignore) {
db.StoreAndClose()
}
}

func createRepositories(config *lib.Config, args []string, opts *newOptions) []error {
func createRepositories(config *rrh.Config, args []string, opts *newOptions) []error {
var errors = []error{}
var db, err = lib.Open(config)
var db, err = rrh.Open(config)
defer storeDbWhenSucceeded(db, errors)
if err != nil {
return []error{err}
}
for _, arg := range args[1:] {
if err := createRepository(db, arg, opts); err != nil {
if isOnError(config, lib.FailImmediately) {
if isOnError(config, rrh.FailImmediately) {
return []error{err}
}
errors = append(errors, err)
Expand All @@ -231,7 +231,7 @@ func createRepositories(config *lib.Config, args []string, opts *newOptions) []e
return errors
}

func perform(config *lib.Config, args []string, opts *newOptions) int {
func perform(config *rrh.Config, args []string, opts *newOptions) int {
if opts.helpFlag {
fmt.Println(getHelpMessage())
return 0
Expand All @@ -241,7 +241,7 @@ func perform(config *lib.Config, args []string, opts *newOptions) int {
}

func goMain(args []string) int {
var config = lib.OpenConfig()
var config = rrh.OpenConfig()
var flag, opts = buildFlagSet(config)
if err := flag.Parse(args); err != nil {
fmt.Println(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions rrh.go → cmd/rrh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"strings"

"github.com/mitchellh/cli"
"github.com/tamada/rrh"
"github.com/tamada/rrh/internal"
"github.com/tamada/rrh/lib"
)

func executeInternalCommand(commands map[string]cli.CommandFactory, args []string) (int, error) {
var c = cli.NewCLI("rrh", lib.VERSION)
var c = cli.NewCLI("rrh", rrh.VERSION)
c.Name = "rrh"
c.Args = args
c.Autocomplete = true
Expand Down Expand Up @@ -104,7 +104,7 @@ func executeExternalCommand(args []string) (int, error) {

func (opts *rrhOptions) updateConfigPath() {
if opts.configPath != "" {
os.Setenv(lib.RrhConfigPath, opts.configPath)
os.Setenv(rrh.ConfigPath, opts.configPath)
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/colorable_output.go → colorable_output.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package rrh

import (
"strings"
Expand Down Expand Up @@ -124,8 +124,8 @@ The function is automatically called on loading the config file.
*/
func InitializeColor(config *Config) *Color {
var color = Color{colorSettings{}, colorFuncs{}}
var settingString = config.GetValue(RrhColor)
if config.IsSet(RrhEnableColorized) && settingString != "" {
var settingString = config.GetValue(ColorSetting)
if config.IsSet(EnableColorized) && settingString != "" {
color.parse(settingString)
}
color.updateFuncs()
Expand Down
6 changes: 3 additions & 3 deletions lib/colorable_output_test.go → colorable_output_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package rrh

import (
"os"
Expand All @@ -8,9 +8,9 @@ import (
)

func TestEnableColorize(t *testing.T) {
os.Setenv(RrhConfigPath, "../testdata/config.json")
os.Setenv(ConfigPath, "testdata/config.json")
var config = OpenConfig()
config.Update(RrhEnableColorized, "true")
config.Update(EnableColorized, "true")
var cs = InitializeColor(config)

var groupName1 = cs.ColorizedGroupName("group")
Expand Down

0 comments on commit 3e24b0a

Please sign in to comment.