Skip to content

Commit

Permalink
import: No need to error for no matches if using glob pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Sep 22, 2016
1 parent bbf954c commit d60a26a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion caddyfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package caddyfile

import (
"io"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -237,7 +238,11 @@ func (p *parser) doImport() error {
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
}
if len(matches) == 0 {
return p.Errf("No files matching import pattern %s", importPattern)
if strings.Contains(globPattern, "*") {
log.Printf("[WARNING] No files matching import pattern: %s", importPattern)
} else {
return p.Errf("File to import not found: %s", importPattern)
}
}

// splice out the import directive and its argument (2 tokens total)
Expand Down
3 changes: 3 additions & 0 deletions caddyfile/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ func TestParseAll(t *testing.T) {
{"glob1.host0"},
{"glob2.host0"},
}},

{`import notfound/*`, false, [][]string{}}, // glob needn't error with no matches
{`import notfound/file.conf`, true, [][]string{}}, // but a specific file should
} {
p := testParser(test.input)
blocks, err := p.parseAll()
Expand Down

0 comments on commit d60a26a

Please sign in to comment.