Code commentary
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ahsanul Haque · committed by spf13 · parent 4745f1f · Browse files · 2 files·+13 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+13 added−6 removed
- other:+13 added−6 removed
Provenance
- Commit
e1e66f7- Tree
1fe53f8- Author
Ahsanul Haque <ahsanul@gmail.com>- Committer
spf13 <steve.francia@gmail.com>- Parent
4745f1f
2 files changed+13 added−6 removed
modified:cobra.go+6 added
29 unmodified lines30 // automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.31 // Set this to true to enable it32 var EnablePrefixMatching bool = false33 34+//OnInitialize takes a series of func() arguments and appends them to a slice of func().35 func OnInitialize(y ...func()) {36 for _, x := range y {37 initializers = append(initializers, x)38 }39 }40 41+//Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,42+//Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as43+//ints and then compared.44 func Gt(a interface{}, b interface{}) bool {45 var left, right int6446 av := reflect.ValueOf(a)47 19 unmodified lines67 68 return left > right69 }70 71+//Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.72 func Eq(a interface{}, b interface{}) bool {73 av := reflect.ValueOf(a)74 bv := reflect.ValueOf(b)75 7 unmodified lines83 }84 return false85 }86 87+//rpad adds padding to the right of a string88 func rpad(s string, padding int) string {89 template := fmt.Sprintf("%%-%ds", padding)90 return fmt.Sprintf(template, s)91 }13 unmodified linesmodified:command.go+7 added-6 removed
9 unmodified lines10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11 // See the License for the specific language governing permissions and12 // limitations under the License.13 14-// Commands similar to git, go tools and other modern CLI tools15-// inspired by go, go-Commander, gh and subcommand16-14+//Package cobra is a commander providing a simple interface to create powerful modern CLI interfaces.15+//In addition to providing an interface, Cobra simultaneously provides a controller to organize your application code.16 package cobra17 18 import (19 "bytes"37 unmodified lines57 58 flagErrorBuf *bytes.Buffer59 cmdErrorBuf *bytes.Buffer60 62- args []string61+ args []string // actual args parsed from flags62 output *io.Writer // nil means stderr; use Out() method instead63 usageFunc func(*Command) error // Usage can be defined by application64 usageTemplate string // Can be defined by Application65 helpTemplate string // Can be defined by Application105 unmodified lines171 }172 173 var minCommandPathPadding int = 11174 175+//176 func (c *Command) CommandPathPadding() int {177 if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {178 return minCommandPathPadding179 } else {325 unmodified lines505 c.cmdErrorBuf = new(bytes.Buffer)506 c.cmdErrorBuf.Reset()507 }508 509+//Commands returns a slice of child commands.510 func (c *Command) Commands() []*Command {511 return c.commands512 }513 513-// Add one or many commands as children of this514+// AddCommand adds one or more commands to this parent command.515 func (c *Command) AddCommand(cmds ...*Command) {516 for i, x := range cmds {517 if cmds[i] == c {518 panic("Command can't be a child of itself")55 unmodified lines574 c.output = tmpOutput575 return bb.String()576 }577 577-// The full path to this command578+// CommandPath returns the full path to this command.579 func (c *Command) CommandPath() string {580 str := c.Name()581 x := c582 for x.HasParent() {208 unmodified lines