From af25f0254e94eb2e2898ba495bfc3de209a49e79 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 22 Aug 2019 13:38:37 -0600 Subject: caddyfile: Support global config block; allow non-empty blocks w/ 0 keys --- caddyconfig/caddyfile/dispenser.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'caddyconfig/caddyfile/dispenser.go') diff --git a/caddyconfig/caddyfile/dispenser.go b/caddyconfig/caddyfile/dispenser.go index 66a3541..93f451e 100755 --- a/caddyconfig/caddyfile/dispenser.go +++ b/caddyconfig/caddyfile/dispenser.go @@ -186,10 +186,10 @@ func (d *Dispenser) File() string { // Args is a convenience function that loads the next arguments // (tokens on the same line) into an arbitrary number of strings -// pointed to in targets. If there are fewer tokens available -// than string pointers, the remaining strings will not be changed -// and false will be returned. If there were enough tokens available -// to fill the arguments, then true will be returned. +// pointed to in targets. If there are not enough argument tokens +// available to fill targets, false is returned and the remaining +// targets are left unchanged. If all the targets are filled, +// then true is returned. func (d *Dispenser) Args(targets ...*string) bool { for i := 0; i < len(targets); i++ { if !d.NextArg() { @@ -200,6 +200,21 @@ func (d *Dispenser) Args(targets ...*string) bool { return true } +// AllArgs is like Args, but if there are more argument tokens +// available than there are targets, false is returned. The +// number of available argument tokens must match the number of +// targets exactly to return true. +func (d *Dispenser) AllArgs(targets ...*string) bool { + if !d.Args(targets...) { + return false + } + if d.NextArg() { + d.Prev() + return false + } + return true +} + // RemainingArgs loads any more arguments (tokens on the same line) // into a slice and returns them. Open curly brace tokens also indicate // the end of arguments, and the curly brace is not included in -- cgit v1.2.3