From 71e3acacd2ea8254236025195101171ab0506a17 Mon Sep 17 00:00:00 2001 From: Artem Nezvigin Date: Fri, 13 Jun 2014 20:09:28 -0700 Subject: [PATCH] Add FlagNames() method to Context It's often useful to list all defined flags prior to launching the program for debugging/logging purposes. This takes away the boilerplate. --- context.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/context.go b/context.go index b2c51bb..5c65c32 100644 --- a/context.go +++ b/context.go @@ -105,6 +105,18 @@ func (c *Context) IsSet(name string) bool { return c.setFlags[name] == true } +// Returns a slice of flag names used in this context. +func (c *Context) FlagNames() (names []string) { + for _, flag := range c.Command.Flags { + name := strings.Split(flag.getName(), ",")[0] + if name == "help" { + continue + } + names = append(names, name) + } + return +} + type Args []string // Returns the command line arguments associated with the context.