diff --git a/cmd/doc-scraper/exec_test.go b/cmd/doc-scraper/exec_test.go index 75ebdfd..764336c 100644 --- a/cmd/doc-scraper/exec_test.go +++ b/cmd/doc-scraper/exec_test.go @@ -164,6 +164,17 @@ func TestResolveSiteKeys(t *testing.T) { _, _, ok = resolveSiteKeys("", "", false) assert.False(t, ok) + + // A -sites list with no keys selects nothing, so it is not a selector. + for _, sites := range []string{",", " , ,", " "} { + _, _, ok = resolveSiteKeys("", sites, false) + assert.False(t, ok, "-sites %q", sites) + } + + keys, warning, ok = resolveSiteKeys("a", ",", false) + assert.True(t, ok) + assert.Equal(t, []string{"a"}, keys) + assert.Equal(t, "-sites has no site keys; using -site", warning) } func TestLogHelpers(t *testing.T) { diff --git a/cmd/doc-scraper/main.go b/cmd/doc-scraper/main.go index 9e8e177..4f3beb6 100644 --- a/cmd/doc-scraper/main.go +++ b/cmd/doc-scraper/main.go @@ -167,6 +167,8 @@ func extraArgsError(fs *flag.FlagSet) error { // resolveSiteKeys picks the crawl target in precedence --all-sites > -sites > // -site. warning is non-empty when a lower-precedence selector was also set and // silently ignored, so a typo'd -site next to a valid -sites is not missed. +// A -sites list with no keys in it (e.g. ",") counts as not given; if -site +// is also set it is used, with a warning. func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, warning string, ok bool) { if allSites { if sites != "" || siteKey != "" { @@ -174,20 +176,23 @@ func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, w } return nil, warning, true } - if sites != "" { + for _, s := range strings.Split(sites, ",") { + s = strings.TrimSpace(s) + if s != "" { + siteKeys = append(siteKeys, s) + } + } + if len(siteKeys) > 0 { if siteKey != "" { warning = "both -site and -sites given; using -sites and ignoring -site" } - for _, s := range strings.Split(sites, ",") { - s = strings.TrimSpace(s) - if s != "" { - siteKeys = append(siteKeys, s) - } - } return siteKeys, warning, true } if siteKey != "" { - return []string{siteKey}, "", true + if sites != "" { + warning = "-sites has no site keys; using -site" + } + return []string{siteKey}, warning, true } return nil, "", false }