src/server/pkg/cmdutil/cobra.go
func CreateAlias(cmd *cobra.Command, invocation string) *cobra.Command {

	// Create logical commands for each substring in each invocation
	var root, prev *cobra.Command
	args := strings.Split(invocation, " ")

	for i, arg := range args {
		cur := &cobra.Command{}

		// The leaf command node should include the usage from the given cmd,
		// while logical nodes just need one piece of the invocation.
		if i == len(args)-1 {
			*cur = *cmd
			if cmd.Use == "" {
				cur.Use = arg
			} else {
				cur.Use = strings.Replace(cmd.Use, "{{alias}}", arg, -1)
			}
			cur.Example = strings.Replace(cmd.Example, "{{alias}}", fmt.Sprintf("%s %s", os.Args[0], invocation), -1)
		} else {
			cur.Use = arg
		}

		if root == nil {
			root = cur
		} else if prev != nil {
			prev.AddCommand(cur)
		}
		prev = cur
	}

	return root
}
func CreateAlias(cmd *cobra.Command, invocation string) *cobra.Command {

	// Create logical commands for each substring in each invocation
	var root, prev *cobra.Command
	args := strings.Split(invocation, " ")

	for i, arg := range args {
		cur := &cobra.Command{}

		// The leaf command node should include the usage from the given cmd,
		// while logical nodes just need one piece of the invocation.
		if i == len(args)-1 {
			*cur = *cmd
			if cmd.Use == "" {
				cur.Use = arg
			} else {
				cur.Use = strings.Replace(cmd.Use, "{{alias}}", arg, -1)
			}
			cur.Example = strings.Replace(cmd.Example, "{{alias}}", fmt.Sprintf("%s %s", os.Args[0], invocation), -1)
		} else {
			cur.Use = arg
		}

		if root == nil {
			root = cur
		} else if prev != nil {
			prev.AddCommand(cur)
		}
		prev = cur
	}

	return root
}
func CreateAlias ( cmd * cobra . Command , invocation string ) * cobra . Command { // Create logical commands for each substring in each invocation var root , prev * cobra . Command args := strings . Split ( invocation , " " ) for i , arg := range args { cur := & cobra . Command { } // The leaf command node should include the usage from the given cmd, // while logical nodes just need one piece of the invocation. if i == len ( args ) - 1 { * cur = * cmd if cmd . Use == " " { cur . Use = arg } else { cur . Use = strings . Replace ( cmd . Use , " " , arg , - 1 ) } cur . Example = strings . Replace ( cmd . Example , " " , fmt . Sprintf ( " " , os . Args [ 0 ] , invocation ) , - 1 ) } else { cur . Use = arg } if root == nil { root = cur } else if prev != nil { prev . AddCommand ( cur ) } prev = cur } return root }
// CreateAlias generates a nested command tree for the invocation specified,
// which should be space-delimited as on the command-line.  The 'Use' field of
// 'cmd' should specify '{{alias}}' instead of the command name as that will be
// filled in based on each invocation.  Similarly, for the 'Example' field,
// '{{alias}}' will be replaced with the full command path.  These commands can
// later be merged into the final Command tree using 'MergeCommands' below.
CreateAlias generates a nested command tree for the invocation specified which should be space - delimited as on the command - line . The Use field of cmd should specify {{ alias }} instead of the command name as that will be filled in based on each invocation . Similarly for the Example field {{ alias }} will be replaced with the full command path . These commands can later be merged into the final Command tree using MergeCommands below .