當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cmd.Main函數代碼示例

本文整理匯總了Golang中code/cloudfoundry/org/cli/cf/cmd.Main函數的典型用法代碼示例。如果您正苦於以下問題:Golang Main函數的具體用法?Golang Main怎麽用?Golang Main使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Main函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Execute

func (cmd *ApiCommand) Execute(args []string) error {
	if cmd.Config.Experimental() == false {
		oldCmd.Main(os.Getenv("CF_TRACE"), os.Args)
		return nil
	}

	cmd.UI.DisplayText("This command is in EXPERIMENTAL stage and may change without notice")
	cmd.UI.DisplayNewline()

	if cmd.Unset {
		return cmd.ClearTarget()
	}

	if cmd.OptionalArgs.URL != "" {
		err := cmd.SetAPI()
		if err != nil {
			return err
		}
	}

	if cmd.Config.Target() == "" {
		cmd.UI.DisplayText("No api endpoint set. Use '{{.Name}}' to set an endpoint", map[string]interface{}{
			"Name": "cf api",
		})
		return nil
	}

	return DisplayCurrentTargetInformation(cmd.Config, cmd.UI)
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:29,代碼來源:api_command.go

示例2: Execute

func (cmd UnbindServiceCommand) Execute(args []string) error {
	if cmd.Config.Experimental() == false {
		oldCmd.Main(os.Getenv("CF_TRACE"), os.Args)
		return nil
	}

	cmd.UI.DisplayText("This command is in EXPERIMENTAL stage and may change without notice")
	cmd.UI.DisplayNewline()

	err := common.CheckTarget(cmd.Config, true, true)
	if err != nil {
		return err
	}

	space := cmd.Config.TargetedSpace()
	user, err := cmd.Config.CurrentUser()
	if err != nil {
		return err
	}

	cmd.UI.DisplayHeaderFlavorText("Unbinding app {{.AppName}} from service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{
		"AppName":     cmd.RequiredArgs.AppName,
		"ServiceName": cmd.RequiredArgs.ServiceInstanceName,
		"OrgName":     cmd.Config.TargetedOrganization().Name,
		"SpaceName":   space.Name,
		"CurrentUser": user.Name,
	})

	warnings, err := cmd.Actor.UnbindServiceBySpace(cmd.RequiredArgs.AppName, cmd.RequiredArgs.ServiceInstanceName, space.GUID)
	cmd.UI.DisplayWarnings(warnings)
	if err != nil {
		if _, ok := err.(v2actions.ServiceBindingNotFoundError); ok {
			cmd.UI.DisplayWarning("Binding between {{.InstanceName}} and {{.AppName}} did not exist", map[string]interface{}{
				"AppName":      cmd.RequiredArgs.AppName,
				"InstanceName": cmd.RequiredArgs.ServiceInstanceName,
			})
		} else {
			return common.HandleError(err)
		}
	}

	cmd.UI.DisplayOK()

	return nil
}
開發者ID:cloudfoundry,項目名稱:v3-cli-plugin,代碼行數:45,代碼來源:unbind_service_command.go

示例3: Execute

func (_ RestartAppInstanceCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:restart_app_instance_command.go

示例4: Execute

func (_ UnsharePrivateDomainCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:unshare_private_domain_command.go

示例5: Execute

func (_ RunningEnvironmentVariableGroupCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:running_environment_variable_group_command.go

示例6: Execute

func (_ UnsetOrgRoleCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:unset_org_role_command.go

示例7: Execute

func (_ SpaceSSHAllowedCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:space_ssh_allowed_command.go

示例8: Execute

func (_ DeleteSpaceQuotaCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:delete_space_quota_command.go

示例9: Execute

func (_ RemovePluginRepoCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:remove_plugin_repo_command.go

示例10: Execute

func (_ RouterGroupsCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:router_groups_command.go

示例11: Execute

func (_ CreateAppManifestCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:create_app_manifest_command.go

示例12: Execute

func (_ DisableServiceAccessCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:disable_service_access_command.go

示例13: Execute

func (_ InstallPluginCommand) Execute(args []string) error {
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:4,代碼來源:install_plugin_command.go

示例14: parse

func parse(args []string) {
	parser := flags.NewParser(&v2.Commands, flags.HelpFlag)
	parser.CommandHandler = executionWrapper
	extraArgs, err := parser.ParseArgs(args)
	if err == nil {
		return
	}

	if flagErr, ok := err.(*flags.Error); ok {
		switch flagErr.Type {
		case flags.ErrHelp, flags.ErrUnknownFlag, flags.ErrExpectedArgument:
			_, found := reflect.TypeOf(v2.Commands).FieldByNameFunc(
				func(fieldName string) bool {
					field, _ := reflect.TypeOf(v2.Commands).FieldByName(fieldName)
					return parser.Active != nil && parser.Active.Name == field.Tag.Get("command")
				},
			)

			if found && flagErr.Type == flags.ErrUnknownFlag && parser.Active.Name == "set-env" {
				newArgs := []string{}
				for _, arg := range args {
					if arg[0] == '-' {
						newArgs = append(newArgs, fmt.Sprintf("%s%s", v2.WorkAroundPrefix, arg))
					} else {
						newArgs = append(newArgs, arg)
					}
				}
				parse(newArgs)
				return
			}

			if flagErr.Type == flags.ErrUnknownFlag || flagErr.Type == flags.ErrExpectedArgument {
				fmt.Fprintf(os.Stderr, "Incorrect Usage: %s\n\n", flagErr.Error())
			}

			if found {
				parse([]string{"help", parser.Active.Name})
			} else {
				switch len(extraArgs) {
				case 0:
					parse([]string{"help"})
				case 1:
					if !isOption(extraArgs[0]) || (len(args) > 1 && extraArgs[0] == "-a") {
						parse([]string{"help", extraArgs[0]})
					} else {
						parse([]string{"help"})
					}
				default:
					if isCommand(extraArgs[0]) {
						parse([]string{"help", extraArgs[0]})
					} else {
						parse(extraArgs[1:])
					}
				}
			}

			if flagErr.Type == flags.ErrUnknownFlag || flagErr.Type == flags.ErrExpectedArgument {
				os.Exit(1)
			}
		case flags.ErrRequired:
			fmt.Fprintf(os.Stderr, "Incorrect Usage: %s\n\n", flagErr.Error())
			parse([]string{"help", args[0]})
			os.Exit(1)
		case flags.ErrUnknownCommand:
			cmd.Main(os.Getenv("CF_TRACE"), os.Args)
		case flags.ErrCommandRequired:
			if v2.Commands.VerboseOrVersion {
				parse([]string{"version"})
			} else {
				parse([]string{"help"})
			}
		default:
			fmt.Fprintf(os.Stderr, "Unexpected flag error\ntype: %s\nmessage: %s\n", flagErr.Type, flagErr.Error())
		}
	} else if err == ErrFailed {
		os.Exit(1)
	} else {
		fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error())
		os.Exit(1)
	}
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:81,代碼來源:main.go

示例15: Execute

func (_ SetEnvCommand) Execute(args []string) error {
	//TODO: Be sure to sanitize the WorkAroundPrefix
	cmd.Main(os.Getenv("CF_TRACE"), os.Args)
	return nil
}
開發者ID:fujitsu-cf,項目名稱:cli,代碼行數:5,代碼來源:set_env_command.go


注:本文中的code/cloudfoundry/org/cli/cf/cmd.Main函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。