Skip to content

Commit 5db6516

Browse files
authored
Merge pull request #282 from erizocosmico/feature/globs
cmd/gitbase: glob support for adding repositories
2 parents b1509a5 + b55d517 commit 5db6516

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

cmd/gitbase/command/server.go

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package command
22

33
import (
44
"net"
5+
"path/filepath"
56
"strconv"
67

78
"github.com/src-d/gitbase"
@@ -28,8 +29,8 @@ const (
2829
// Server represents the `server` command of gitbase cli tool.
2930
type Server struct {
3031
Verbose bool `short:"v" description:"Activates the verbose mode"`
31-
Git []string `short:"g" long:"git" description:"Path where the git repositories are located, multiple directories can be defined"`
32-
Siva []string `long:"siva" description:"Path where the siva repositories are located, multiple directories can be defined"`
32+
Git []string `short:"g" long:"git" description:"Path where the git repositories are located, multiple directories can be defined. Accepts globs."`
33+
Siva []string `long:"siva" description:"Path where the siva repositories are located, multiple directories can be defined. Accepts globs."`
3334
Host string `short:"h" long:"host" default:"localhost" description:"Host where the server is going to listen"`
3435
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen"`
3536
User string `short:"u" long:"user" default:"root" description:"User name used for connection"`
@@ -116,27 +117,49 @@ func (c *Server) addDirectories() error {
116117
logrus.Error("At least one git folder or siva folder should be provided.")
117118
}
118119

119-
for _, dir := range c.Git {
120-
if err := c.addGitDirectory(dir); err != nil {
120+
for _, pattern := range c.Git {
121+
if err := c.addGitPattern(pattern); err != nil {
121122
return err
122123
}
123124
}
124125

125-
for _, dir := range c.Siva {
126-
if err := c.addSivaDirectory(dir); err != nil {
126+
for _, pattern := range c.Siva {
127+
if err := c.addSivaPattern(pattern); err != nil {
127128
return err
128129
}
129130
}
130131

131132
return nil
132133
}
133134

134-
func (c *Server) addGitDirectory(folder string) error {
135-
logrus.WithField("dir", c.Git).Debug("git repositories directory added")
136-
return c.pool.AddDir(folder)
135+
func (c *Server) addGitPattern(pattern string) error {
136+
matches, err := filepath.Glob(pattern)
137+
if err != nil {
138+
return err
139+
}
140+
141+
for _, m := range matches {
142+
logrus.WithField("dir", m).Debug("git repositories directory added")
143+
if err := c.pool.AddDir(m); err != nil {
144+
return err
145+
}
146+
}
147+
148+
return nil
137149
}
138150

139-
func (c *Server) addSivaDirectory(folder string) error {
140-
logrus.WithField("dir", c.Git).Debug("siva repositories directory added")
141-
return c.pool.AddSivaDir(folder)
151+
func (c *Server) addSivaPattern(pattern string) error {
152+
matches, err := filepath.Glob(pattern)
153+
if err != nil {
154+
return err
155+
}
156+
157+
for _, m := range matches {
158+
logrus.WithField("dir", m).Debug("siva repositories directory added")
159+
if err := c.pool.AddSivaDir(m); err != nil {
160+
return err
161+
}
162+
}
163+
164+
return nil
142165
}

0 commit comments

Comments
 (0)