Skip to content

Commit 02b8ade

Browse files
committed
git-bundle-server: add 'list' command
Add a new 'git-bundle-server' command to list the routes that are currently configured and their remote Git URLs. Update manpage and 'README.md' with description and usage information. Due to how routes are currently stored in the bundle server, only "active" routes are listed (that is, routes that have not been stopped with 'git-bundle-server stop'). This is intended to be only a temporary issue, with future updates to how routes are stored allowing better tracking of "stopped" routes. Signed-off-by: Victoria Dye <[email protected]>
1 parent ad55484 commit 02b8ade

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ being managed by the bundle server.
133133
* `git-bundle-server delete <route>`: Remove the configuration for the given
134134
`<route>` and delete its repository data.
135135

136+
* `git-bundle-server list [<options>]`: List each route and associated
137+
information (e.g. Git remote URL) in the bundle server.
138+
136139
### Web server management
137140

138141
Independent of the management of the individual repositories hosted by the

cmd/git-bundle-server/list.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/github/git-bundle-server/cmd/utils"
9+
"github.com/github/git-bundle-server/internal/argparse"
10+
"github.com/github/git-bundle-server/internal/core"
11+
"github.com/github/git-bundle-server/internal/git"
12+
"github.com/github/git-bundle-server/internal/log"
13+
)
14+
15+
type listCmd struct {
16+
logger log.TraceLogger
17+
container *utils.DependencyContainer
18+
}
19+
20+
func NewListCommand(logger log.TraceLogger, container *utils.DependencyContainer) argparse.Subcommand {
21+
return &listCmd{
22+
logger: logger,
23+
container: container,
24+
}
25+
}
26+
27+
func (listCmd) Name() string {
28+
return "list"
29+
}
30+
31+
func (listCmd) Description() string {
32+
return `
33+
List the routes registered to the bundle server.`
34+
}
35+
36+
func (l *listCmd) Run(ctx context.Context, args []string) error {
37+
parser := argparse.NewArgParser(l.logger, "git-bundle-server list [--name-only]")
38+
nameOnly := parser.Bool("name-only", false, "print only the names of configured routes")
39+
parser.Parse(ctx, args)
40+
41+
repoProvider := utils.GetDependency[core.RepositoryProvider](ctx, l.container)
42+
gitHelper := utils.GetDependency[git.GitHelper](ctx, l.container)
43+
44+
repos, err := repoProvider.GetRepositories(ctx)
45+
if err != nil {
46+
return l.logger.Error(ctx, err)
47+
}
48+
49+
for _, repo := range repos {
50+
info := []string{repo.Route}
51+
if !*nameOnly {
52+
remote, err := gitHelper.GetRemoteUrl(ctx, repo.RepoDir)
53+
if err != nil {
54+
return l.logger.Error(ctx, err)
55+
}
56+
info = append(info, remote)
57+
}
58+
59+
// Join with space & tab to ensure each element of the info array is
60+
// separated by at least two spaces (for better readability).
61+
fmt.Println(strings.Join(info, " \t"))
62+
}
63+
64+
return nil
65+
}

cmd/git-bundle-server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func all(logger log.TraceLogger) []argparse.Subcommand {
1919
NewStopCommand(logger, container),
2020
NewUpdateCommand(logger, container),
2121
NewUpdateAllCommand(logger, container),
22+
NewListCommand(logger, container),
2223
NewWebServerCommand(logger, container),
2324
}
2425
}

docs/man/git-bundle-server.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ fetching during scheduled bundle updates.
8484
*delete* _route_::
8585
Remove a repository configuration and delete its data on disk.
8686

87+
*list* [*--name-only*]::
88+
List the routes registered to the bundle server. Each line in the output
89+
represents a unique route and includes (in order) the route name and the Git
90+
remote URL associated with that route.
91+
92+
*--name-only*:::
93+
Print only the route name on each line.
94+
8795
*web-server* *start* [*-f*|*--force*] [_server-options_]::
8896
Start a background process web server hosting bundle metadata and content. The
8997
web server daemon runs under the calling user's domain, and will continue

0 commit comments

Comments
 (0)