Skip to content

Commit 51bee59

Browse files
authored
Merge pull request #389 from erizocosmico/fix/version-cmd
cmd/gitbase: fix version and build info
2 parents 8c43654 + ecde5d7 commit 51bee59

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

cmd/gitbase/command/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Server struct {
4747
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well." env:"GITBASE_READONLY"`
4848
// SkipGitErrors disables failing when Git errors are found.
4949
SkipGitErrors bool
50+
// Version of the application.
51+
Version string
5052

5153
engine *sqle.Engine
5254
pool *gitbase.RepositoryPool
@@ -137,7 +139,7 @@ func (c *Server) buildDatabase() error {
137139
ab = ab.ReadOnly()
138140
}
139141
a := ab.Build()
140-
c.engine = sqle.New(catalog, a, version)
142+
c.engine = sqle.New(catalog, a, c.Version)
141143
}
142144

143145
c.pool = gitbase.NewRepositoryPool()

cmd/gitbase/command/version.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ const (
77
VersionHelp = VersionDescription
88
)
99

10-
var (
11-
version = "undefined"
12-
build = "undefined"
13-
)
14-
1510
// Version represents the `version` command of gitbase cli tool.
1611
type Version struct {
1712
// Name of the cli binary
1813
Name string
14+
// Version of the cli binary
15+
Version string
16+
// Build of the cli binary
17+
Build string
1918
}
2019

2120
// Execute prints the build information provided by the compilation tools, it
2221
// honors the go-flags.Commander interface.
2322
func (c *Version) Execute(args []string) error {
24-
fmt.Printf("%s (%s) - build %s\n", c.Name, version, build)
23+
fmt.Printf("%s (%s) - build %s\n", c.Name, c.Version, c.Build)
2524
return nil
2625
}

cmd/gitbase/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
)
1111

1212
const (
13-
name = "gitbase"
13+
name = "gitbase"
14+
version = "undefined"
15+
build = "undefined"
1416
)
1517

1618
func main() {
@@ -19,14 +21,17 @@ func main() {
1921
_, err := parser.AddCommand("server", command.ServerDescription, command.ServerHelp,
2022
&command.Server{
2123
SkipGitErrors: os.Getenv("GITBASE_SKIP_GIT_ERRORS") != "",
24+
Version: version,
2225
})
2326
if err != nil {
2427
logrus.Fatal(err)
2528
}
2629

2730
_, err = parser.AddCommand("version", command.VersionDescription, command.VersionHelp,
2831
&command.Version{
29-
Name: name,
32+
Name: name,
33+
Version: version,
34+
Build: build,
3035
})
3136
if err != nil {
3237
logrus.Fatal(err)

0 commit comments

Comments
 (0)