Skip to content

Commit c7f5edd

Browse files
committed
git-bundle-server: add 'version' command
Add a command to report the version of the compiled bundle server executables. The version string is set using the '-ldflags' build flag in 'go build' (specifically, setting the 'Version' string in 'cmd/utils/version.go'). In a later patch, the version will be automatically during the build process (using 'make') with 'git describe'. Signed-off-by: Victoria Dye <[email protected]>
1 parent 0a8b690 commit c7f5edd

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

cmd/git-bundle-server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func all(logger log.TraceLogger) []argparse.Subcommand {
2121
NewUpdateCommand(logger, container),
2222
NewUpdateAllCommand(logger, container),
2323
NewListCommand(logger, container),
24+
NewVersionCommand(logger, container),
2425
NewWebServerCommand(logger, container),
2526
}
2627
}

cmd/git-bundle-server/version.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/github/git-bundle-server/cmd/utils"
8+
"github.com/github/git-bundle-server/internal/argparse"
9+
"github.com/github/git-bundle-server/internal/log"
10+
)
11+
12+
type versionCmd struct {
13+
logger log.TraceLogger
14+
container *utils.DependencyContainer
15+
}
16+
17+
func NewVersionCommand(logger log.TraceLogger, container *utils.DependencyContainer) argparse.Subcommand {
18+
return &versionCmd{
19+
logger: logger,
20+
container: container,
21+
}
22+
}
23+
24+
func (versionCmd) Name() string {
25+
return "version"
26+
}
27+
28+
func (versionCmd) Description() string {
29+
return `
30+
Display the version information for the bundle server CLI.`
31+
}
32+
33+
func (v *versionCmd) Run(ctx context.Context, args []string) error {
34+
parser := argparse.NewArgParser(v.logger, "git-bundle-server version")
35+
parser.Parse(ctx, args)
36+
37+
versionStr := utils.Version
38+
if versionStr == "" {
39+
versionStr = "<no version>"
40+
}
41+
42+
fmt.Printf("git-bundle-server version %s\n", versionStr)
43+
44+
return nil
45+
}

cmd/utils/version.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package utils
2+
3+
// The purpose of this file is to contain globally-accessible variables that
4+
// specify version information for the bundle server. The values of these
5+
// variables are set during the build process when using 'make'.
6+
7+
// The executable's version string with no leading 'v' (e.g. "1.0.0" or
8+
// "1.0.1-g1a2b3c4d").
9+
var Version string

docs/man/git-bundle-server.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ the server.
5353

5454
== COMMANDS
5555

56+
*version*::
57+
Display the version information for the bundle server CLI
58+
5659
*init* _url_ [_route_]::
5760
Initialize a repository for which bundles should be served. The repository is
5861
cloned into a bare repo from _url_. A base bundle is created for the

0 commit comments

Comments
 (0)