本文整理汇总了Golang中github.com/spf13/cobra.Command.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Parent方法的具体用法?Golang Command.Parent怎么用?Golang Command.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Parent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addACBuildAnnotation
func addACBuildAnnotation(cmd *cobra.Command, args []string) error {
const annoNamePattern = "appc.io/acbuild/command-%d"
acb := newACBuild()
man, err := util.GetManifest(acb.CurrentACIPath)
if err != nil {
return err
}
var acbuildCount int
for _, ann := range man.Annotations {
var tmpCount int
n, _ := fmt.Sscanf(string(ann.Name), annoNamePattern, &tmpCount)
if n == 1 && tmpCount > acbuildCount {
acbuildCount = tmpCount
}
}
command := cmd.Name()
tmpcmd := cmd.Parent()
for {
command = tmpcmd.Name() + " " + command
if tmpcmd == cmdAcbuild {
break
}
tmpcmd = tmpcmd.Parent()
}
for _, a := range args {
command += fmt.Sprintf(" %q", a)
}
return acb.AddAnnotation(fmt.Sprintf(annoNamePattern, acbuildCount+1), command)
}
示例2: isInitDriverManagersCmd
func (c *CLI) isInitDriverManagersCmd(cmd *cobra.Command) bool {
return cmd.Parent() != nil &&
cmd != c.adapterCmd &&
cmd != c.adapterGetTypesCmd &&
cmd != c.versionCmd &&
c.isServiceCmd(cmd) &&
c.isModuleCmd(cmd)
}
示例3: flagName
func flagName(cmd *cobra.Command, name string) string {
parentName := doit.NSRoot
if cmd.Parent() != nil {
parentName = cmd.Parent().Name()
}
return fmt.Sprintf("%s-%s-%s", parentName, cmd.Name(), name)
}
示例4: cmdNS
func cmdNS(cmd *cobra.Command) string {
parentName := doit.NSRoot
if cmd.Parent() != nil {
parentName = cmd.Parent().Name()
}
return fmt.Sprintf("%s-%s", parentName, cmd.Name())
}
示例5: tokenType
func tokenType(cmd *cobra.Command) string {
if cmd.Parent().Name() == "team" {
return tokenTeamManage
}
if asMember, _ := cmd.Flags().GetString("as-member"); asMember != "" {
return tokenTeamAccess
}
return tokenPersonal
}
示例6: GenMarkdownCustom
func GenMarkdownCustom(cmd *cobra.Command, out io.Writer, linkHandler func(string) string) {
name := cmd.CommandPath()
short := cmd.Short
long := cmd.Long
if len(long) == 0 {
long = short
}
fmt.Fprintf(out, "## %s\n\n", name)
fmt.Fprintf(out, "%s\n\n", short)
fmt.Fprintf(out, "### Synopsis\n\n")
fmt.Fprintf(out, "\n%s\n\n", long)
if cmd.Runnable() {
fmt.Fprintf(out, "```\n%s\n```\n\n", cmd.UseLine())
}
if len(cmd.Example) > 0 {
fmt.Fprintf(out, "### Examples\n\n")
fmt.Fprintf(out, "```\n%s\n```\n\n", cmd.Example)
}
printOptions(out, cmd, name)
if hasSeeAlso(cmd) {
fmt.Fprintf(out, "### SEE ALSO\n")
if cmd.HasParent() {
parent := cmd.Parent()
pname := parent.CommandPath()
link := pname + ".md"
link = strings.Replace(link, " ", "_", -1)
fmt.Fprintf(out, "* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short)
cmd.VisitParents(func(c *cobra.Command) {
if c.DisableAutoGenTag {
cmd.DisableAutoGenTag = c.DisableAutoGenTag
}
})
}
children := cmd.Commands()
sort.Sort(byName(children))
for _, child := range children {
if !child.IsAvailableCommand() || child.IsHelpCommand() {
continue
}
cname := name + " " + child.Name()
link := cname + ".md"
link = strings.Replace(link, " ", "_", -1)
fmt.Fprintf(out, "* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short)
}
fmt.Fprintf(out, "\n")
}
if !cmd.DisableAutoGenTag {
fmt.Fprintf(out, "###### Auto generated by spf13/cobra on %s\n", time.Now().Format("2-Jan-2006"))
}
}
示例7: IsSiblingCommandExists
// IsSiblingCommandExists receives a pointer to a cobra command and a target string.
// Returns true if the target string is found in the list of sibling commands.
func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool {
for _, c := range cmd.Parent().Commands() {
if c.Name() == targetCmdName {
return true
}
}
return false
}
示例8: missingFlag
func missingFlag(cmd *cobra.Command, name string) (Result, error) {
util.Errorf("No option -%s specified!\n", hostPathFlag)
text := cmd.Name()
parent := cmd.Parent()
if parent != nil {
text = parent.Name() + " " + text
}
util.Infof("Please try something like: %s --%s='some value' ...\n\n", text, hostPathFlag)
return Failure, nil
}
示例9: AddCommand
func AddCommand(parent *cobra.Command, cmd *cobra.Command, local bool) *cobra.Command {
parent.AddCommand(cmd)
for i := range extensions {
ext := &extensions[i]
if ext.run == false && local == ext.local && ext.After == cmd.Name() {
ext.Func(cmd.Parent())
ext.run = true
}
}
return cmd
}
示例10: findChildOfRootCommand
func findChildOfRootCommand(command *cobra.Command) (*cobra.Command, bool) {
for command.HasParent() {
if !command.Parent().HasParent() {
return command, true
}
command = command.Parent()
}
return nil, false
}
示例11: genMan
func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
// something like `rootcmd subcmd1 subcmd2`
commandName := cmd.CommandPath()
// something like `rootcmd-subcmd1-subcmd2`
dashCommandName := strings.Replace(commandName, " ", "-", -1)
fillHeader(header, commandName)
buf := new(bytes.Buffer)
short := cmd.Short
long := cmd.Long
if len(long) == 0 {
long = short
}
manPreamble(buf, header, commandName, short, long)
manPrintOptions(buf, cmd)
if len(cmd.Example) > 0 {
fmt.Fprintf(buf, "# EXAMPLE\n")
fmt.Fprintf(buf, "```\n%s\n```\n", cmd.Example)
}
if hasSeeAlso(cmd) {
fmt.Fprintf(buf, "# SEE ALSO\n")
seealsos := make([]string, 0)
if cmd.HasParent() {
parentPath := cmd.Parent().CommandPath()
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
seealsos = append(seealsos, seealso)
cmd.VisitParents(func(c *cobra.Command) {
if c.DisableAutoGenTag {
cmd.DisableAutoGenTag = c.DisableAutoGenTag
}
})
}
children := cmd.Commands()
sort.Sort(byName(children))
for _, c := range children {
if !c.IsAvailableCommand() || c.IsHelpCommand() {
continue
}
seealso := fmt.Sprintf("**%s-%s(%s)**", dashCommandName, c.Name(), header.Section)
seealsos = append(seealsos, seealso)
}
fmt.Fprintf(buf, "%s\n", strings.Join(seealsos, ", "))
}
if !cmd.DisableAutoGenTag {
fmt.Fprintf(buf, "# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006"))
}
return buf.Bytes()
}
示例12: Complete
// Complete completes the options for the Openshift cli status command.
func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, baseCLIName string, args []string, out io.Writer) error {
if len(args) > 0 {
return kcmdutil.UsageError(cmd, "no arguments should be provided")
}
o.logsCommandName = fmt.Sprintf("%s logs", cmd.Parent().CommandPath())
o.securityPolicyCommandFormat = "oadm policy add-scc-to-user anyuid -n %s -z %s"
o.setProbeCommandName = fmt.Sprintf("%s set probe", cmd.Parent().CommandPath())
client, kclient, kclientset, err := f.Clients()
if err != nil {
return err
}
config, err := f.OpenShiftClientConfig.ClientConfig()
if err != nil {
return err
}
if o.allNamespaces {
o.namespace = kapi.NamespaceAll
} else {
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.namespace = namespace
}
if baseCLIName == "" {
baseCLIName = "oc"
}
o.describer = &describe.ProjectStatusDescriber{
OldK: kclient,
K: kclientset,
C: client,
Server: config.Host,
Suggest: o.verbose,
CommandBaseName: baseCLIName,
// TODO: Remove these and reference them inside the markers using constants.
LogsCommandName: o.logsCommandName,
SecurityPolicyCommandFormat: o.securityPolicyCommandFormat,
SetProbeCommandName: o.setProbeCommandName,
}
o.out = out
return nil
}
示例13: RunCompletion
func RunCompletion(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmdutil.UsageError(cmd, "Shell not specified.")
}
if len(args) > 1 {
return cmdutil.UsageError(cmd, "Too many arguments. Expected only the shell type.")
}
run, found := completion_shells[args[0]]
if !found {
return cmdutil.UsageError(cmd, "Unsupported shell type %q.", args[0])
}
return run(out, cmd.Parent())
}
示例14: Complete
// Complete verifies command line arguments and loads data from the command environment
func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []string, argsLenAtDash int) error {
// Let kubectl exec follow rules for `--`, see #13004 issue
if len(p.PodName) == 0 && (len(argsIn) == 0 || argsLenAtDash == 0) {
return cmdutil.UsageError(cmd, execUsageStr)
}
if len(p.PodName) != 0 {
printDeprecationWarning("exec POD_NAME", "-p POD_NAME")
if len(argsIn) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
p.Command = argsIn
} else {
p.PodName = argsIn[0]
p.Command = argsIn[1:]
if len(p.Command) < 1 {
return cmdutil.UsageError(cmd, execUsageStr)
}
}
cmdParent := cmd.Parent()
if cmdParent != nil {
p.FullCmdName = cmdParent.CommandPath()
}
if len(p.FullCmdName) > 0 && cmdutil.IsSiblingCommandExists(cmd, "describe") {
p.SuggestedCmdUsage = fmt.Sprintf("Use '%s describe pod/%s' to see all of the containers in this pod.", p.FullCmdName, p.PodName)
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
p.Namespace = namespace
config, err := f.ClientConfig()
if err != nil {
return err
}
p.Config = config
clientset, err := f.ClientSet()
if err != nil {
return err
}
p.PodClient = clientset.Core()
return nil
}
示例15: isInitDriverManagersCmd
func isInitDriverManagersCmd(cmd *cobra.Command) bool {
return cmd.Parent() != nil &&
cmd != adapterCmd &&
cmd != adapterGetTypesCmd &&
cmd != versionCmd &&
cmd != serviceCmd &&
cmd != serviceInitSysCmd &&
cmd != installCmd &&
cmd != uninstallCmd &&
cmd != serviceStatusCmd &&
cmd != serviceStopCmd &&
!(cmd == serviceStartCmd && (client != "" || fg || force)) &&
cmd != moduleCmd &&
cmd != moduleTypesCmd &&
cmd != moduleInstancesCmd &&
cmd != moduleInstancesListCmd
}