Skip to content

Commit 7d50f22

Browse files
authored
Merge pull request #237 from mcuadros/cmd-multiple-dir
cmd: server, support multiple siva and git folders
2 parents 5861159 + 48f25cb commit 7d50f22

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

cmd/gitbase/server.go

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"errors"
54
"net"
65
"os"
76
"strconv"
@@ -25,12 +24,12 @@ var enableUnstableSquash = os.Getenv("UNSTABLE_SQUASH_ENABLE") != ""
2524
type cmdServer struct {
2625
Verbose bool `short:"v" description:"Activates the verbose mode"`
2726

28-
Git string `short:"g" long:"git" description:"Path where the git repositories are located"`
29-
Siva string `long:"siva" description:"Path where the siva repositories are located"`
30-
Host string `short:"h" long:"host" default:"localhost" description:"Host where the server is going to listen"`
31-
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen"`
32-
User string `short:"u" long:"user" default:"root" description:"User name used for connection"`
33-
Password string `short:"P" long:"password" default:"" description:"Password used for connection"`
27+
Git []string `short:"g" long:"git" description:"Path where the git repositories are located, multiple directories can be defined"`
28+
Siva []string `long:"siva" description:"Path where the siva repositories are located, multiple directories can be defined"`
29+
Host string `short:"h" long:"host" default:"localhost" description:"Host where the server is going to listen"`
30+
Port int `short:"p" long:"port" default:"3306" description:"Port where the server is going to listen"`
31+
User string `short:"u" long:"user" default:"root" description:"User name used for connection"`
32+
Password string `short:"P" long:"password" default:"" description:"Password used for connection"`
3433

3534
engine *sqle.Engine
3635
pool *gitbase.RepositoryPool
@@ -42,30 +41,15 @@ func (c *cmdServer) buildDatabase() error {
4241
c.engine = sqle.New()
4342
}
4443

45-
if c.Git == "" && c.Siva == "" {
46-
return errors.New("missing git or siva directories")
47-
}
48-
4944
c.pool = gitbase.NewRepositoryPool()
5045

51-
if c.Git != "" {
52-
logrus.WithField("dir", c.Git).Debug("added folder containing git repositories")
53-
54-
if err := c.pool.AddDir(c.Git); err != nil {
55-
return err
56-
}
57-
}
58-
59-
if c.Siva != "" {
60-
logrus.WithField("dir", c.Siva).Debug("added folder containing siva repositories")
61-
62-
if err := c.pool.AddSivaDir(c.Siva); err != nil {
63-
return err
64-
}
46+
if err := c.addDirectories(); err != nil {
47+
return err
6548
}
6649

6750
c.engine.AddDatabase(gitbase.NewDatabase(c.name))
6851
logrus.WithField("db", c.name).Debug("registered database to catalog")
52+
6953
c.engine.Catalog.RegisterFunctions(function.Functions)
7054
logrus.Debug("registered all available functions in catalog")
7155

@@ -106,7 +90,36 @@ func (c *cmdServer) Execute(args []string) error {
10690
return err
10791
}
10892

109-
logrus.Debug("starting server")
110-
93+
logrus.Info("starting server")
11194
return s.Start()
11295
}
96+
97+
func (c *cmdServer) addDirectories() error {
98+
if len(c.Git) == 0 && len(c.Siva) == 0 {
99+
logrus.Error("At least one git folder or siva folder should be provided.")
100+
}
101+
102+
for _, dir := range c.Git {
103+
if err := c.addGitDirectory(dir); err != nil {
104+
return err
105+
}
106+
}
107+
108+
for _, dir := range c.Siva {
109+
if err := c.addSivaDirectory(dir); err != nil {
110+
return err
111+
}
112+
}
113+
114+
return nil
115+
}
116+
117+
func (c *cmdServer) addGitDirectory(folder string) error {
118+
logrus.WithField("dir", c.Git).Debug("git repositories directory added")
119+
return c.pool.AddDir(folder)
120+
}
121+
122+
func (c *cmdServer) addSivaDirectory(folder string) error {
123+
logrus.WithField("dir", c.Git).Debug("siva repositories directory added")
124+
return c.pool.AddSivaDir(folder)
125+
}

0 commit comments

Comments
 (0)