From 30d83a70a74d10fb102eef50c131a91607ccb90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B8dseth?= Date: Fri, 15 Nov 2013 11:30:45 +0100 Subject: [PATCH] Added two convenience functions for retrieving arguments --- context.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/context.go b/context.go index 877aaa1..d944d70 100644 --- a/context.go +++ b/context.go @@ -129,3 +129,17 @@ func (c *Context) lookupBool(name string, set *flag.FlagSet) bool { return false } + +// Returns the nth argument, or just a blank string +func (c *Context) GetArg(n int) string { + args := c.Args() + if len(args) < n { + return args[n] + } + return "" +} + +// Returns the first argument, or just a blank string, for convenience +func (c *Context) FirstArg() string { + return c.GetArg(0) +}