Documentation ¶
Overview ¶
Package cmdns provides namespacing to Cobra command's subcommands Command namespacing is an alternative way to structure sub commands, similar to `rake db:migrate` and `ovrclk apps:create`.
Example ¶
package main import ( "fmt" "github.com/gosuri/cmdns" "github.com/spf13/cobra" ) var runFunc = func(cmd *cobra.Command, args []string) { fmt.Println("run", cmd.Name()) } func main() { ovrclk := &cobra.Command{Use: "ovrclk"} apps := &cobra.Command{Use: "apps"} apps.AddCommand(&cobra.Command{Use: "info", Run: runFunc}) ovrclk.AddCommand(apps) // Enable namespacing cmdns.Namespace(ovrclk) ovrclk.Execute() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultNamespacer is the default namespacer for the package DefaultNamespacer = New() // DefaultNamespaceSeperator is the char that seperates commands DefaultNamespaceSeperator = ':' )
Functions ¶
Types ¶
type CobraNamespace ¶
type CobraNamespace struct { OverrideUsageFunc bool // contains filtered or unexported fields }
CobraNamespace represents a namespace for a command. This is usually then second level command.
func NewCobraNamespace ¶
func NewCobraNamespace() *CobraNamespace
NewCobraNamespace returns a new Namespace
func (*CobraNamespace) AvailableCommands ¶
func (n *CobraNamespace) AvailableCommands() []*cobra.Command
AvailableCommands returns the namespaced commands that are available
func (*CobraNamespace) Command ¶
func (n *CobraNamespace) Command() *cobra.Command
Command returns the command for the namespace
type CobraNamespacer ¶
type CobraNamespacer struct { // Namespaces is the collection of cobra namespaces Namespaces []*CobraNamespace OverrideUsageFunc bool }
CobraNamespacer is the struct represting the component that namespaces cobra's sucommands
func SetOverrideUsageFunc ¶
func SetOverrideUsageFunc(v bool) *CobraNamespacer
SetOverrideUsageFunc when set to true will overide the command's usage function with the package's usage function that displays namespaces using the default namespacer
func (*CobraNamespacer) Namespace ¶
func (c *CobraNamespacer) Namespace(cmd *cobra.Command) error
Namespace enables namespacing for the command's subcommands
func (*CobraNamespacer) SetOverrideUsageFunc ¶
func (c *CobraNamespacer) SetOverrideUsageFunc(v bool) *CobraNamespacer
SetOverrideUsageFunc when set to true will overide the command's usage function with the package's usage function that displays namespaces