()
| 58 | } |
| 59 | |
| 60 | func newAppPresenter() appPresenter { |
| 61 | var presenter appPresenter |
| 62 | |
| 63 | pluginPath := filepath.Join(confighelpers.PluginRepoDir(), ".cf", "plugins") |
| 64 | |
| 65 | pluginConfig := pluginconfig.NewPluginConfig( |
| 66 | func(err error) { |
| 67 | // fail silently when running help |
| 68 | }, |
| 69 | configuration.NewDiskPersistor(filepath.Join(pluginPath, "config.json")), |
| 70 | pluginPath, |
| 71 | ) |
| 72 | |
| 73 | plugins := pluginConfig.Plugins() |
| 74 | |
| 75 | maxNameLen := commandregistry.Commands.MaxCommandNameLength() |
| 76 | maxNameLen = maxPluginCommandNameLength(plugins, maxNameLen) |
| 77 | |
| 78 | presentCommand := func(commandName string) (presenter cmdPresenter) { |
| 79 | cmd := commandregistry.Commands.FindCommand(commandName) |
| 80 | presenter.Name = cmd.MetaData().Name |
| 81 | padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(presenter.Name)) |
| 82 | presenter.Name = presenter.Name + padding |
| 83 | presenter.Description = cmd.MetaData().Description |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | presentPluginCommands := func() []cmdPresenter { |
| 88 | var presenters []cmdPresenter |
| 89 | var pluginPresenter cmdPresenter |
| 90 | |
| 91 | for _, pluginMetadata := range plugins { |
| 92 | for _, cmd := range pluginMetadata.Commands { |
| 93 | pluginPresenter.Name = cmd.Name |
| 94 | |
| 95 | padding := strings.Repeat(" ", maxNameLen-utf8.RuneCountInString(pluginPresenter.Name)) |
| 96 | pluginPresenter.Name = pluginPresenter.Name + padding |
| 97 | pluginPresenter.Description = cmd.HelpText |
| 98 | presenters = append(presenters, pluginPresenter) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return presenters |
| 103 | } |
| 104 | |
| 105 | presenter.Name = os.Args[0] |
| 106 | presenter.Usage = T("A command line tool to interact with Cloud Foundry") |
| 107 | presenter.Version = version.VersionString() |
| 108 | presenter.Commands = []groupedCommands{ |
| 109 | { |
| 110 | Name: T("GETTING STARTED"), |
| 111 | CommandSubGroups: [][]cmdPresenter{ |
| 112 | { |
| 113 | presentCommand("help"), |
| 114 | presentCommand("version"), |
| 115 | presentCommand("login"), |
| 116 | presentCommand("logout"), |
| 117 | presentCommand("passwd"), |
no test coverage detected