aboutsummaryrefslogtreecommitdiff
path: root/cmd/pkgsite
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-08-26 06:53:02 -0400
committerJonathan Amsterdam <jba@google.com>2021-08-26 14:35:39 +0000
commit59bb0edbee4758dd62c17e8924afc35e234d198a (patch)
tree0b2572fe564085d283d0a7082912262e717b031a /cmd/pkgsite
parentf6f5076d4026eb90c4e6603f2b56b86402fc0bfb (diff)
downloadgo-x-pkgsite-59bb0edbee4758dd62c17e8924afc35e234d198a.tar.xz
cmd/pkgsite: accept space-separated paths too
Treat any command-line argument as a path or comma-separated list of paths. For golang/go#47780 Change-Id: I5d9044d3ff0e14af99c4632f3c723039179a94a5 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/345270 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'cmd/pkgsite')
-rw-r--r--cmd/pkgsite/main.go23
-rw-r--r--cmd/pkgsite/main_test.go10
2 files changed, 29 insertions, 4 deletions
diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go
index 0110008f..95895fa0 100644
--- a/cmd/pkgsite/main.go
+++ b/cmd/pkgsite/main.go
@@ -23,7 +23,9 @@ package main
import (
"context"
"flag"
+ "fmt"
"net/http"
+ "os"
"strings"
"time"
@@ -47,15 +49,20 @@ var (
)
func main() {
+ flag.Usage = func() {
+ fmt.Fprintf(flag.CommandLine.Output(), "usage: %s [flags] [PATHS ...]\n", os.Args[0])
+ fmt.Fprintf(flag.CommandLine.Output(), " where PATHS is a single path or a comma-separated list\n")
+ flag.PrintDefaults()
+ }
flag.Parse()
ctx := context.Background()
- paths := flag.Arg(0)
- if paths == "" {
- paths = "."
+ paths := collectPaths(flag.Args())
+ if len(paths) == 0 {
+ paths = []string{"."}
}
- server, err := newServer(ctx, strings.Split(paths, ","), *gopathMode)
+ server, err := newServer(ctx, paths, *gopathMode)
if err != nil {
log.Fatalf(ctx, "newServer: %v", err)
}
@@ -66,6 +73,14 @@ func main() {
log.Fatal(ctx, http.ListenAndServe(*httpAddr, mw(router)))
}
+func collectPaths(args []string) []string {
+ var paths []string
+ for _, arg := range args {
+ paths = append(paths, strings.Split(arg, ",")...)
+ }
+ return paths
+}
+
func newServer(ctx context.Context, paths []string, gopathMode bool) (*frontend.Server, error) {
getters := buildGetters(ctx, paths, gopathMode)
lds := fetchdatasource.Options{
diff --git a/cmd/pkgsite/main_test.go b/cmd/pkgsite/main_test.go
index f0db81d1..b7490764 100644
--- a/cmd/pkgsite/main_test.go
+++ b/cmd/pkgsite/main_test.go
@@ -10,6 +10,8 @@ import (
"net/http"
"net/http/httptest"
"testing"
+
+ "github.com/google/go-cmp/cmp"
)
func Test(t *testing.T) {
@@ -27,3 +29,11 @@ func Test(t *testing.T) {
t.Errorf("%q: got status code = %d, want %d", "/testmod", w.Code, http.StatusOK)
}
}
+
+func TestCollectPaths(t *testing.T) {
+ got := collectPaths([]string{"a", "b,c2,d3", "e4", "f,g"})
+ want := []string{"a", "b", "c2", "d3", "e4", "f", "g"}
+ if !cmp.Equal(got, want) {
+ t.Errorf("got %v, want %v", got, want)
+ }
+}