mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-24 01:26:47 +01:00
Added support magic characters in import pattern
Import now allows to use the star wildcard, question mark and square brackets as used by filepath.Glob
This commit is contained in:
parent
5b93799a62
commit
12f594779c
1 changed files with 16 additions and 1 deletions
|
@ -184,11 +184,26 @@ func (p *parser) doImport() error {
|
|||
if !p.NextArg() {
|
||||
return p.ArgErr()
|
||||
}
|
||||
importFile := p.Val()
|
||||
importPattern := p.Val()
|
||||
if p.NextArg() {
|
||||
return p.Err("Import allows only one file to import")
|
||||
}
|
||||
|
||||
matches, err := filepath.Glob(importPattern)
|
||||
if err != nil {
|
||||
return p.Errf("Failed to use import pattern %s - %s", importPattern, err.Error())
|
||||
}
|
||||
|
||||
for _, importFile := range matches {
|
||||
if err := p.doSingleImport(importFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parser) doSingleImport(importFile string) error {
|
||||
file, err := os.Open(importFile)
|
||||
if err != nil {
|
||||
return p.Errf("Could not import %s - %v", importFile, err)
|
||||
|
|
Loading…
Reference in a new issue