From af56c5033c18ef45685f8df743736634999c7dc3 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 16 Mar 2015 11:23:17 -0600 Subject: [PATCH] New method to get remaining arguments on a line --- config/dispenser.go | 18 ++++++++++++++++++ middleware/middleware.go | 1 + 2 files changed, 19 insertions(+) diff --git a/config/dispenser.go b/config/dispenser.go index 2d251121..cfd685e3 100644 --- a/config/dispenser.go +++ b/config/dispenser.go @@ -145,3 +145,21 @@ func (d *dispenser) Args(targets ...*string) bool { } return enough } + +// RemainingArgs is a convenience function that loads any more arguments +// (tokens on the same line) into a slice and returns them. Open curly +// brace tokens indicate the end of arguments (the curly brace is not +// included). +func (d *dispenser) RemainingArgs() []string { + var args []string + + for d.NextArg() { + if d.Val() == "{" { + d.cursor-- + break + } + args = append(args, d.Val()) + } + + return args +} diff --git a/middleware/middleware.go b/middleware/middleware.go index 041c34b9..72d2208d 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -23,6 +23,7 @@ type ( NextBlock() bool Val() string Args(...*string) bool + RemainingArgs() []string ArgErr() error Err(string) error Startup(func() error)