From 40f18800b20df8f74ad2b02aa4e56748a3d17239 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Wed, 11 Oct 2017 16:15:37 +0200 Subject: [PATCH] Delete name field from Command (#547) Discussion: https://github.com/spf13/cobra/pull/422#discussion_r143918343 --- command.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/command.go b/command.go index 87d0791c..4d4b391e 100644 --- a/command.go +++ b/command.go @@ -128,8 +128,6 @@ type Command struct { // TraverseChildren parses flags on all parents before executing child command. TraverseChildren bool - // name is the command name, usually the executable's name. - name string // commands is the list of commands supported by this program. commands []*Command // parent is a parent command for this command. @@ -1047,15 +1045,12 @@ func (c *Command) DebugFlags() { // Name returns the command's name: the first word in the use line. func (c *Command) Name() string { - if c.name == "" { - name := c.Use - i := strings.Index(name, " ") - if i >= 0 { - name = name[:i] - } - c.name = name + name := c.Use + i := strings.Index(name, " ") + if i >= 0 { + name = name[:i] } - return c.name + return name } // HasAlias determines if a given string is an alias of the command.