Code commentary
This commit is contained in:
13
command.go
13
command.go
@ -11,9 +11,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Commands similar to git, go tools and other modern CLI tools
|
||||
// inspired by go, go-Commander, gh and subcommand
|
||||
|
||||
//Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.
|
||||
//In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.
|
||||
package cobra
|
||||
|
||||
import (
|
||||
@ -59,7 +58,7 @@ type Command struct {
|
||||
flagErrorBuf *bytes.Buffer
|
||||
cmdErrorBuf *bytes.Buffer
|
||||
|
||||
args []string
|
||||
args []string // actual args parsed from flags
|
||||
output *io.Writer // nil means stderr; use Out() method instead
|
||||
usageFunc func(*Command) error // Usage can be defined by application
|
||||
usageTemplate string // Can be defined by Application
|
||||
@ -173,6 +172,7 @@ func (c *Command) UsagePadding() int {
|
||||
|
||||
var minCommandPathPadding int = 11
|
||||
|
||||
//
|
||||
func (c *Command) CommandPathPadding() int {
|
||||
if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {
|
||||
return minCommandPathPadding
|
||||
@ -506,11 +506,12 @@ func (c *Command) ResetCommands() {
|
||||
c.cmdErrorBuf.Reset()
|
||||
}
|
||||
|
||||
//Commands returns a slice of child commands.
|
||||
func (c *Command) Commands() []*Command {
|
||||
return c.commands
|
||||
}
|
||||
|
||||
// Add one or many commands as children of this
|
||||
// AddCommand adds one or more commands to this parent command.
|
||||
func (c *Command) AddCommand(cmds ...*Command) {
|
||||
for i, x := range cmds {
|
||||
if cmds[i] == c {
|
||||
@ -574,7 +575,7 @@ func (c *Command) UsageString() string {
|
||||
return bb.String()
|
||||
}
|
||||
|
||||
// The full path to this command
|
||||
// CommandPath returns the full path to this command.
|
||||
func (c *Command) CommandPath() string {
|
||||
str := c.Name()
|
||||
x := c
|
||||
|
Reference in New Issue
Block a user