Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/doc-scraper/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 13 additions & 8 deletions cmd/doc-scraper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,32 @@ 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 != "" {
warning = "--all-sites is set; ignoring -site/-sites"
}
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
}
Expand Down
Loading