Skip to content

Commit

Permalink
Merge pull request #8 from tadashi-aikawa/0.7.0
Browse files Browse the repository at this point in the history
0.7.0
  • Loading branch information
tadashi-aikawa committed Feb 23, 2019
2 parents ca77b1d + 4b701c6 commit 7e44a6a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 26 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Support for both Windows and Linux.

![DEMO](https://raw.githubusercontent.com/tadashi-aikawa/gowl/master/demo.gif)


Install
-------

Expand Down Expand Up @@ -57,9 +58,20 @@ Quick start
```toml
root = "Root directory of repositories for gowl"
# ex. C:\\users\\tadashi-aikawa\\.gowl

browser = "Your browser"
# ex. C:\\Program Files (x86)\\Google\\Chrome\\Application\\Chrome.exe

subSpaces = [
"Subspaces that can be used for purposes other than Get 1",
"Subspaces that can be used for purposes other than Get 2",
]
# ex. [
# "C:\\Users\\tadashi-aikawa\\tmp",
# "C:\\Users\\tadashi-aikawa\\works",
# ]


[editors]
default = "code"
vim = "vim"
Expand Down
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/pkg/errors"
)

const version = "0.6.0"
const version = "0.7.0"
const usage = `Gowl.
Usage:
Expand Down
34 changes: 23 additions & 11 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import (

const gowlSite = "gowl.site"

func concat(elm string, elms []string) []string {
rets := []string{elm}
for _, x := range elms {
rets = append(rets, x)
}
return rets
}

func toSelection(r Repository) string {
return fmt.Sprintf("*%-5v %-45v %-10v %v", r.Star, r.FullName, r.Language, r.License)
}
Expand Down Expand Up @@ -89,9 +97,8 @@ func getCommandStdout(workdir *string, name string, arg ...string) (string, erro
}

// selectLocalRepository returns repository path.
func selectLocalRepository(root string) (string, error) {
repoRoot := filepath.Join(root)
repoDirs, err := listRepositories(repoRoot)
func selectLocalRepository(dirs []string) (string, error) {
repoDirs, err := listRepositories(dirs)
if err != nil {
return "", errors.Wrap(err, "Fail to search repositories")
}
Expand Down Expand Up @@ -205,8 +212,9 @@ func CmdGet(handler IHandler, root string, force bool, shallow bool, recursive b
}

// CmdList executes `open`
func CmdList(handler IHandler, root string) error {
repositories, err := listRepositories(root)
func CmdList(handler IHandler, root string, subSpaces []string) error {
dirs := concat(root, subSpaces)
repositories, err := listRepositories(dirs)
if err != nil {
return errors.Wrap(err, "Fail to search repository.")
}
Expand All @@ -216,8 +224,9 @@ func CmdList(handler IHandler, root string) error {
}

// CmdEdit executes `edit`
func CmdEdit(handler IHandler, root string, editor string) error {
selection, err := selectLocalRepository(root)
func CmdEdit(handler IHandler, root string, subSpaces []string, editor string) error {
dirs := concat(root, subSpaces)
selection, err := selectLocalRepository(dirs)
if selection == "" {
return nil
}
Expand All @@ -233,8 +242,10 @@ func CmdEdit(handler IHandler, root string, editor string) error {
}

// CmdPurge purges...
func CmdPurge(handler IHandler, root string) error {
selection, err := selectLocalRepository(root)
func CmdPurge(handler IHandler, root string, subSpaces []string) error {
dirs := concat(root, subSpaces)

selection, err := selectLocalRepository(dirs)
if selection == "" {
return nil
}
Expand Down Expand Up @@ -268,8 +279,9 @@ func CmdPurge(handler IHandler, root string) error {
}

// CmdWeb executes `web`
func CmdWeb(handler IHandler, root string, browser string) error {
selection, err := selectLocalRepository(root)
func CmdWeb(handler IHandler, root string, subSpaces []string, browser string) error {
dirs := concat(root, subSpaces)
selection, err := selectLocalRepository(dirs)
if selection == "" {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
Editors map[string]string
Browser string
Root string
SubSpaces []string
GitHub Service
BitbucketServer Service
}
Expand All @@ -37,7 +38,6 @@ func CreateConfig() (Config, error) {
}

configPath := filepath.Join(home, ".gowlconfig")

var conf Config
if _, err := toml.DecodeFile(configPath, &conf); err != nil {
return Config{}, err
Expand Down
33 changes: 24 additions & 9 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (
"golang.org/x/oauth2"
)

func contains(elms []string, elm string) bool {
for _, e := range elms {
if e == elm {
return true
}
}

return false
}

// Repository used by gowl
type Repository struct {
FullName string
Expand Down Expand Up @@ -105,17 +115,22 @@ func createGithubClient(token string) *github.Client {
return github.NewClient(tc)
}

func listRepositories(dir string) ([]string, error) {
func listRepositories(dirs []string) ([]string, error) {
var gitDirs []string
err := filepath.Walk(dir, func(cpath string, info os.FileInfo, err error) error {
if _, err := os.Stat(filepath.Join(cpath, ".git")); err == nil {
gitDirs = append(gitDirs, cpath)
return filepath.SkipDir
for _, dir := range dirs {
err := filepath.Walk(dir, func(cpath string, info os.FileInfo, err error) error {
if contains([]string{"node_modules", "_build", "build", "dist"}, filepath.Base(cpath)) {
return filepath.SkipDir
}
if _, err := os.Stat(filepath.Join(cpath, ".git")); err == nil {
gitDirs = append(gitDirs, cpath)
return filepath.SkipDir
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "Fail to search repositories.")
}
return nil
})
if err != nil {
return nil, errors.Wrap(err, "Fail to search repositories.")
}

return gitDirs, nil
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ func main() {
log.Fatal(errors.Wrap(err, "Fail to command `get`"))
}
case args.CmdEdit:
if err := CmdEdit(handler, getRoot(config), config.Editors[args.Editor]); err != nil {
if err := CmdEdit(handler, getRoot(config), config.SubSpaces, config.Editors[args.Editor]); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `edit`"))
}
case args.CmdWeb:
if err := CmdWeb(handler, getRoot(config), config.Browser); err != nil {
if err := CmdWeb(handler, getRoot(config), config.SubSpaces, config.Browser); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `web`"))
}
case args.CmdList:
if err := CmdList(handler, getRoot(config)); err != nil {
if err := CmdList(handler, getRoot(config), config.SubSpaces); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `list`"))
}
case args.CmdPurge:
if err := CmdPurge(handler, getRoot(config)); err != nil {
if err := CmdPurge(handler, getRoot(config), config.SubSpaces); err != nil {
log.Fatal(errors.Wrap(err, "Fail to command `purge`"))
}
}
Expand Down

0 comments on commit 7e44a6a

Please sign in to comment.