github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/common/help_command_test.go (about)

     1  //+build !V7
     2  
     3  package common_test
     4  
     5  import (
     6  	"regexp"
     7  
     8  	"code.cloudfoundry.org/cli/actor/actionerror"
     9  	"code.cloudfoundry.org/cli/actor/sharedaction"
    10  	"code.cloudfoundry.org/cli/command/commandfakes"
    11  	. "code.cloudfoundry.org/cli/command/common"
    12  	"code.cloudfoundry.org/cli/command/common/commonfakes"
    13  	"code.cloudfoundry.org/cli/command/flag"
    14  	"code.cloudfoundry.org/cli/util/configv3"
    15  	"code.cloudfoundry.org/cli/util/ui"
    16  
    17  	. "github.com/onsi/ginkgo"
    18  	. "github.com/onsi/gomega"
    19  	. "github.com/onsi/gomega/gbytes"
    20  )
    21  
    22  var _ = Describe("help Command", func() {
    23  	var (
    24  		testUI     *ui.UI
    25  		fakeActor  *commonfakes.FakeHelpActor
    26  		cmd        HelpCommand
    27  		fakeConfig *commandfakes.FakeConfig
    28  	)
    29  
    30  	BeforeEach(func() {
    31  		testUI = ui.NewTestUI(NewBuffer(), NewBuffer(), NewBuffer())
    32  		fakeActor = new(commonfakes.FakeHelpActor)
    33  		fakeConfig = new(commandfakes.FakeConfig)
    34  		fakeConfig.BinaryNameReturns("faceman")
    35  		fakeConfig.BinaryVersionReturns("face2.0-yesterday")
    36  
    37  		cmd = HelpCommand{
    38  			UI:     testUI,
    39  			Actor:  fakeActor,
    40  			Config: fakeConfig,
    41  		}
    42  	})
    43  
    44  	Describe("providing help for a specific command", func() {
    45  		Describe("built-in command", func() {
    46  			BeforeEach(func() {
    47  				cmd.OptionalArgs = flag.CommandName{
    48  					CommandName: "help",
    49  				}
    50  
    51  				commandInfo := sharedaction.CommandInfo{
    52  					Name:        "help",
    53  					Description: "Show help",
    54  					Usage:       "CF_NAME help [COMMAND]",
    55  					Alias:       "h",
    56  				}
    57  				fakeActor.CommandInfoByNameReturns(commandInfo, nil)
    58  			})
    59  
    60  			It("displays the name for help", func() {
    61  				err := cmd.Execute(nil)
    62  				Expect(err).ToNot(HaveOccurred())
    63  
    64  				Expect(testUI.Out).To(Say("NAME:"))
    65  				Expect(testUI.Out).To(Say("   help - Show help"))
    66  
    67  				Expect(fakeActor.CommandInfoByNameCallCount()).To(Equal(1))
    68  				_, commandName := fakeActor.CommandInfoByNameArgsForCall(0)
    69  				Expect(commandName).To(Equal("help"))
    70  			})
    71  
    72  			It("displays the usage for help", func() {
    73  				err := cmd.Execute(nil)
    74  				Expect(err).ToNot(HaveOccurred())
    75  
    76  				Expect(testUI.Out).To(Say("NAME:"))
    77  				Expect(testUI.Out).To(Say("USAGE:"))
    78  				Expect(testUI.Out).To(Say(`   faceman help \[COMMAND\]`))
    79  			})
    80  
    81  			Describe("related commands", func() {
    82  				When("the command has related commands", func() {
    83  					BeforeEach(func() {
    84  						commandInfo := sharedaction.CommandInfo{
    85  							Name:            "app",
    86  							RelatedCommands: []string{"broccoli", "tomato"},
    87  						}
    88  						fakeActor.CommandInfoByNameReturns(commandInfo, nil)
    89  					})
    90  
    91  					It("displays the related commands for help", func() {
    92  						err := cmd.Execute(nil)
    93  						Expect(err).ToNot(HaveOccurred())
    94  
    95  						Expect(testUI.Out).To(Say("NAME:"))
    96  						Expect(testUI.Out).To(Say("SEE ALSO:"))
    97  						Expect(testUI.Out).To(Say("   broccoli, tomato"))
    98  					})
    99  				})
   100  
   101  				When("the command does not have related commands", func() {
   102  					It("displays the related commands for help", func() {
   103  						err := cmd.Execute(nil)
   104  						Expect(err).ToNot(HaveOccurred())
   105  
   106  						Expect(testUI.Out).To(Say("NAME:"))
   107  						Expect(testUI.Out).NotTo(Say("SEE ALSO:"))
   108  					})
   109  				})
   110  			})
   111  
   112  			Describe("aliases", func() {
   113  				When("the command has an alias", func() {
   114  					It("displays the alias for help", func() {
   115  						err := cmd.Execute(nil)
   116  						Expect(err).ToNot(HaveOccurred())
   117  
   118  						Expect(testUI.Out).To(Say("USAGE:"))
   119  						Expect(testUI.Out).To(Say("ALIAS:"))
   120  						Expect(testUI.Out).To(Say("   h"))
   121  					})
   122  				})
   123  
   124  				When("the command does not have an alias", func() {
   125  					BeforeEach(func() {
   126  						cmd.OptionalArgs = flag.CommandName{
   127  							CommandName: "app",
   128  						}
   129  
   130  						commandInfo := sharedaction.CommandInfo{
   131  							Name: "app",
   132  						}
   133  						fakeActor.CommandInfoByNameReturns(commandInfo, nil)
   134  					})
   135  
   136  					It("no alias is displayed", func() {
   137  						err := cmd.Execute(nil)
   138  						Expect(err).ToNot(HaveOccurred())
   139  
   140  						Expect(testUI.Out).ToNot(Say("ALIAS:"))
   141  					})
   142  				})
   143  			})
   144  
   145  			Describe("options", func() {
   146  				When("the command has options", func() {
   147  					BeforeEach(func() {
   148  						cmd.OptionalArgs = flag.CommandName{
   149  							CommandName: "push",
   150  						}
   151  						commandInfo := sharedaction.CommandInfo{
   152  							Name: "push",
   153  							Flags: []sharedaction.CommandFlag{
   154  								{
   155  									Long:        "no-hostname",
   156  									Description: "Map the root domain to this app",
   157  								},
   158  								{
   159  									Short:       "b",
   160  									Description: "Custom buildpack by name (e.g. my-buildpack) or Git URL (e.g. 'https://github.com/cloudfoundry/java-buildpack.git') or Git URL with a branch or tag (e.g. 'https://github.com/cloudfoundry/java-buildpack.git#v3.3.0' for 'v3.3.0' tag). To use built-in buildpacks only, specify 'default' or 'null'",
   161  								},
   162  								{
   163  									Long:        "hostname",
   164  									Short:       "n",
   165  									Description: "Hostname (e.g. my-subdomain)",
   166  								},
   167  								{
   168  									Long:        "force",
   169  									Short:       "f",
   170  									Description: "do it",
   171  									Default:     "yes",
   172  								},
   173  							},
   174  						}
   175  						fakeActor.CommandInfoByNameReturns(commandInfo, nil)
   176  					})
   177  
   178  					Context("only has a long option", func() {
   179  						It("displays the options for app", func() {
   180  							err := cmd.Execute(nil)
   181  							Expect(err).ToNot(HaveOccurred())
   182  
   183  							Expect(testUI.Out).To(Say("USAGE:"))
   184  							Expect(testUI.Out).To(Say("OPTIONS:"))
   185  							Expect(testUI.Out).To(Say(`--no-hostname\s+Map the root domain to this app`))
   186  						})
   187  					})
   188  
   189  					Context("only has a short option", func() {
   190  						It("displays the options for app", func() {
   191  							err := cmd.Execute(nil)
   192  							Expect(err).ToNot(HaveOccurred())
   193  
   194  							Expect(testUI.Out).To(Say("USAGE:"))
   195  							Expect(testUI.Out).To(Say("OPTIONS:"))
   196  							Expect(testUI.Out).To(Say(`-b\s+Custom buildpack by name \(e.g. my-buildpack\) or Git URL \(e.g. 'https://github.com/cloudfoundry/java-buildpack.git'\) or Git URL with a branch or tag \(e.g. 'https://github.com/cloudfoundry/java-buildpack.git#v3.3.0' for 'v3.3.0' tag\). To use built-in buildpacks only, specify 'default' or 'null'`))
   197  						})
   198  					})
   199  
   200  					Context("has long and short options", func() {
   201  						It("displays the options for app", func() {
   202  							err := cmd.Execute(nil)
   203  							Expect(err).ToNot(HaveOccurred())
   204  
   205  							Expect(testUI.Out).To(Say("USAGE:"))
   206  							Expect(testUI.Out).To(Say("OPTIONS:"))
   207  							Expect(testUI.Out).To(Say(`--hostname, -n\s+Hostname \(e.g. my-subdomain\)`))
   208  						})
   209  					})
   210  
   211  					Context("has a default for an option", func() {
   212  						It("displays the default", func() {
   213  							err := cmd.Execute(nil)
   214  							Expect(err).ToNot(HaveOccurred())
   215  
   216  							Expect(testUI.Out).To(Say(`do it \(Default: yes\)`))
   217  						})
   218  					})
   219  				})
   220  			})
   221  		})
   222  
   223  		Describe("Environment", func() {
   224  			Context("has environment variables", func() {
   225  				var envVars []sharedaction.EnvironmentVariable
   226  
   227  				BeforeEach(func() {
   228  					cmd.OptionalArgs = flag.CommandName{
   229  						CommandName: "push",
   230  					}
   231  					envVars = []sharedaction.EnvironmentVariable{
   232  						sharedaction.EnvironmentVariable{
   233  							Name:         "CF_STAGING_TIMEOUT",
   234  							Description:  "Max wait time for buildpack staging, in minutes",
   235  							DefaultValue: "15",
   236  						},
   237  						sharedaction.EnvironmentVariable{
   238  							Name:         "CF_STARTUP_TIMEOUT",
   239  							Description:  "Max wait time for app instance startup, in minutes",
   240  							DefaultValue: "5",
   241  						},
   242  					}
   243  					commandInfo := sharedaction.CommandInfo{
   244  						Name:        "push",
   245  						Environment: envVars,
   246  					}
   247  
   248  					fakeActor.CommandInfoByNameReturns(commandInfo, nil)
   249  				})
   250  
   251  				It("displays the timeouts under environment", func() {
   252  					err := cmd.Execute(nil)
   253  					Expect(err).ToNot(HaveOccurred())
   254  
   255  					Expect(testUI.Out).To(Say("ENVIRONMENT:"))
   256  					Expect(testUI.Out).To(Say(`
   257     CF_STAGING_TIMEOUT=15        Max wait time for buildpack staging, in minutes
   258     CF_STARTUP_TIMEOUT=5         Max wait time for app instance startup, in minutes
   259  `))
   260  				})
   261  			})
   262  
   263  			Context("does not have any associated environment variables", func() {
   264  				BeforeEach(func() {
   265  					cmd.OptionalArgs = flag.CommandName{
   266  						CommandName: "app",
   267  					}
   268  					commandInfo := sharedaction.CommandInfo{
   269  						Name: "app",
   270  					}
   271  
   272  					fakeActor.CommandInfoByNameReturns(commandInfo, nil)
   273  				})
   274  
   275  				It("does not show the environment section", func() {
   276  					err := cmd.Execute(nil)
   277  					Expect(err).ToNot(HaveOccurred())
   278  					Expect(testUI.Out).ToNot(Say("ENVIRONMENT:"))
   279  				})
   280  			})
   281  		})
   282  
   283  		Describe("plug-in command", func() {
   284  			BeforeEach(func() {
   285  				cmd.OptionalArgs = flag.CommandName{
   286  					CommandName: "enable-diego",
   287  				}
   288  
   289  				fakeConfig.PluginsReturns([]configv3.Plugin{
   290  					{Name: "Diego-Enabler",
   291  						Commands: []configv3.PluginCommand{
   292  							{
   293  								Name:     "enable-diego",
   294  								Alias:    "ed",
   295  								HelpText: "enable Diego support for an app",
   296  								UsageDetails: configv3.PluginUsageDetails{
   297  									Usage: "faceman diego-enabler this and that and a little stuff",
   298  									Options: map[string]string{
   299  										"--first":        "foobar",
   300  										"--second-third": "baz",
   301  									},
   302  								},
   303  							},
   304  						},
   305  					},
   306  				})
   307  
   308  				fakeActor.CommandInfoByNameReturns(sharedaction.CommandInfo{},
   309  					actionerror.InvalidCommandError{CommandName: "enable-diego"})
   310  			})
   311  
   312  			It("displays the plugin's help", func() {
   313  				err := cmd.Execute(nil)
   314  				Expect(err).ToNot(HaveOccurred())
   315  
   316  				Expect(testUI.Out).To(Say("enable-diego - enable Diego support for an app"))
   317  				Expect(testUI.Out).To(Say("faceman diego-enabler this and that and a little stuff"))
   318  				Expect(testUI.Out).To(Say("ALIAS:"))
   319  				Expect(testUI.Out).To(Say("ed"))
   320  				Expect(testUI.Out).To(Say(`--first\s+foobar`))
   321  				Expect(testUI.Out).To(Say(`--second-third\s+baz`))
   322  			})
   323  		})
   324  
   325  		Describe("plug-in alias", func() {
   326  			BeforeEach(func() {
   327  				cmd.OptionalArgs = flag.CommandName{
   328  					CommandName: "ed",
   329  				}
   330  
   331  				fakeConfig.PluginsReturns([]configv3.Plugin{
   332  					{
   333  						Name: "Diego-Enabler",
   334  						Commands: []configv3.PluginCommand{
   335  							{
   336  								Name:     "enable-diego",
   337  								Alias:    "ed",
   338  								HelpText: "enable Diego support for an app",
   339  								UsageDetails: configv3.PluginUsageDetails{
   340  									Usage: "faceman diego-enabler this and that and a little stuff",
   341  									Options: map[string]string{
   342  										"--first":        "foobar",
   343  										"--second-third": "baz",
   344  									},
   345  								},
   346  							},
   347  						},
   348  					},
   349  				})
   350  
   351  				fakeActor.CommandInfoByNameReturns(sharedaction.CommandInfo{},
   352  					actionerror.InvalidCommandError{CommandName: "enable-diego"})
   353  			})
   354  
   355  			It("displays the plugin's help", func() {
   356  				err := cmd.Execute(nil)
   357  				Expect(err).ToNot(HaveOccurred())
   358  
   359  				Expect(testUI.Out).To(Say("enable-diego - enable Diego support for an app"))
   360  				Expect(testUI.Out).To(Say("faceman diego-enabler this and that and a little stuff"))
   361  				Expect(testUI.Out).To(Say("ALIAS:"))
   362  				Expect(testUI.Out).To(Say("ed"))
   363  				Expect(testUI.Out).To(Say(`--first\s+foobar`))
   364  				Expect(testUI.Out).To(Say(`--second-third\s+baz`))
   365  			})
   366  		})
   367  	})
   368  
   369  	Describe("help for common commands", func() {
   370  		BeforeEach(func() {
   371  			cmd.OptionalArgs = flag.CommandName{
   372  				CommandName: "",
   373  			}
   374  			cmd.AllCommands = false
   375  			cmd.Actor = sharedaction.NewActor(nil)
   376  		})
   377  
   378  		It("returns a list of only the common commands", func() {
   379  			err := cmd.Execute(nil)
   380  			Expect(err).ToNot(HaveOccurred())
   381  
   382  			Expect(testUI.Out).To(Say("faceman version face2.0-yesterday, Cloud Foundry command line tool"))
   383  			Expect(testUI.Out).To(Say(regexp.QuoteMeta("Usage: faceman [global options] command [arguments...] [command options]")))
   384  
   385  			Expect(testUI.Out).To(Say("Before getting started:"))
   386  			Expect(testUI.Out).To(Say(`  config\s+login,l\s+target,t`))
   387  			Expect(testUI.Out).To(Say(`  help,h\s+logout,lo`))
   388  
   389  			Expect(testUI.Out).To(Say("Application lifecycle:"))
   390  			Expect(testUI.Out).To(Say(`  apps,a\s+run-task,rt\s+events`))
   391  			Expect(testUI.Out).To(Say(`  push,p\s+logs\s+set-env,se`))
   392  			Expect(testUI.Out).To(Say(`  start,st\s+ssh\s+create-app-manifest`))
   393  			Expect(testUI.Out).To(Say(`  stop,sp\s+app\s+delete,d`))
   394  			Expect(testUI.Out).To(Say(`  restart,rs\s+env,e`))
   395  			Expect(testUI.Out).To(Say(`  restage,rg\s+scale`))
   396  
   397  			Expect(testUI.Out).To(Say("Services integration:"))
   398  			Expect(testUI.Out).To(Say(`  marketplace,m\s+create-user-provided-service,cups`))
   399  			Expect(testUI.Out).To(Say(`  services,s\s+update-user-provided-service,uups`))
   400  			Expect(testUI.Out).To(Say(`  create-service,cs\s+create-service-key,csk`))
   401  			Expect(testUI.Out).To(Say(`  update-service\s+delete-service-key,dsk`))
   402  			Expect(testUI.Out).To(Say(`  delete-service,ds\s+service-keys,sk`))
   403  			Expect(testUI.Out).To(Say(`  service\s+service-key`))
   404  			Expect(testUI.Out).To(Say(`  bind-service,bs\s+bind-route-service,brs`))
   405  			Expect(testUI.Out).To(Say(`  unbind-service,us\s+unbind-route-service,urs`))
   406  
   407  			Expect(testUI.Out).To(Say("Route and domain management:"))
   408  			Expect(testUI.Out).To(Say(`  routes,r\s+delete-route\s+create-domain`))
   409  			Expect(testUI.Out).To(Say(`  domains\s+map-route`))
   410  			Expect(testUI.Out).To(Say(`  create-route\s+unmap-route`))
   411  
   412  			Expect(testUI.Out).To(Say("Space management:"))
   413  			Expect(testUI.Out).To(Say(`  spaces\s+create-space\s+set-space-role`))
   414  			Expect(testUI.Out).To(Say(`  space-users\s+delete-space\s+unset-space-role`))
   415  
   416  			Expect(testUI.Out).To(Say("Org management:"))
   417  			Expect(testUI.Out).To(Say(`  orgs,o\s+set-org-role`))
   418  			Expect(testUI.Out).To(Say(`  org-users\s+unset-org-role`))
   419  
   420  			Expect(testUI.Out).To(Say("CLI plugin management:"))
   421  			Expect(testUI.Out).To(Say(`  plugins\s+add-plugin-repo\s+repo-plugins`))
   422  			Expect(testUI.Out).To(Say(`  install-plugin\s+list-plugin-repos`))
   423  
   424  			Expect(testUI.Out).To(Say("Global options:"))
   425  			Expect(testUI.Out).To(Say(`  --help, -h\s+Show help`))
   426  			Expect(testUI.Out).To(Say(`  -v\s+Print API request diagnostics to stdout`))
   427  
   428  			Expect(testUI.Out).To(Say(`TIP: Use 'cf help -a' to see all commands\.`))
   429  		})
   430  
   431  		When("there are multiple installed plugins", func() {
   432  			BeforeEach(func() {
   433  				fakeConfig.PluginsReturns([]configv3.Plugin{
   434  					{
   435  						Name: "Some-other-plugin",
   436  						Commands: []configv3.PluginCommand{
   437  							{
   438  								Name:     "some-other-plugin-command",
   439  								HelpText: "does some other thing",
   440  							},
   441  						},
   442  					},
   443  					{
   444  						Name: "some-plugin",
   445  						Commands: []configv3.PluginCommand{
   446  							{
   447  								Name:     "enable",
   448  								HelpText: "enable command",
   449  							},
   450  							{
   451  								Name:     "disable",
   452  								HelpText: "disable command",
   453  							},
   454  							{
   455  								Name:     "some-other-command",
   456  								HelpText: "does something",
   457  							},
   458  						},
   459  					},
   460  					{
   461  						Name: "the-last-plugin",
   462  						Commands: []configv3.PluginCommand{
   463  							{
   464  								Name:     "last-plugin-command",
   465  								HelpText: "does the last thing",
   466  							},
   467  						},
   468  					},
   469  				})
   470  			})
   471  
   472  			It("returns the plugin commands organized by plugin and sorted in alphabetical order", func() {
   473  				err := cmd.Execute(nil)
   474  				Expect(err).ToNot(HaveOccurred())
   475  
   476  				Expect(testUI.Out).To(Say("Commands offered by installed plugins:"))
   477  				Expect(testUI.Out).To(Say(`some-other-plugin-command\s+enable\s+last-plugin-command`))
   478  				Expect(testUI.Out).To(Say(`disable\s+some-other-command`))
   479  
   480  			})
   481  		})
   482  	})
   483  
   484  	Describe("providing help for all commands", func() {
   485  		When("a command is not provided", func() {
   486  			BeforeEach(func() {
   487  				cmd.OptionalArgs = flag.CommandName{
   488  					CommandName: "",
   489  				}
   490  				cmd.AllCommands = true
   491  
   492  				cmd.Actor = sharedaction.NewActor(nil)
   493  				fakeConfig.PluginsReturns([]configv3.Plugin{
   494  					{
   495  						Name: "Diego-Enabler",
   496  						Commands: []configv3.PluginCommand{
   497  							{
   498  								Name:     "enable-diego",
   499  								HelpText: "enable Diego support for an app",
   500  							},
   501  						},
   502  					},
   503  				})
   504  			})
   505  
   506  			It("returns a list of all commands", func() {
   507  				Expect(cmd.Execute(nil)).ToNot(HaveOccurred())
   508  
   509  				Expect(testUI.Out).To(Say("NAME:"))
   510  				Expect(testUI.Out).To(Say("   faceman - A command line tool to interact with Cloud Foundry"))
   511  				Expect(testUI.Out).To(Say("USAGE:"))
   512  				Expect(testUI.Out).To(Say(`   faceman \[global options\] command \[arguments...\] \[command options\]`))
   513  				Expect(testUI.Out).To(Say("VERSION:"))
   514  				Expect(testUI.Out).To(Say("   face2.0-yesterday"))
   515  				Expect(testUI.Out).To(Say(""))
   516  				Expect(testUI.Out).To(Say("GETTING STARTED:"))
   517  				Expect(testUI.Out).To(Say(`   help\s+Show help`))
   518  				Expect(testUI.Out).To(Say(`   api\s+Set or view target api url`))
   519  				Expect(testUI.Out).To(Say(""))
   520  				Expect(testUI.Out).To(Say("APPS:"))
   521  				Expect(testUI.Out).To(Say(`   apps\s+List all apps in the target space`))
   522  				Expect(testUI.Out).To(Say(`   restart-app-instance\s+Terminate, then restart an app instance`))
   523  				Expect(testUI.Out).To(Say(`   ssh-enabled\s+Reports whether SSH is enabled on an application container instance`))
   524  				Expect(testUI.Out).To(Say(""))
   525  				Expect(testUI.Out).To(Say("SERVICES:"))
   526  				Expect(testUI.Out).To(Say(`   marketplace\s+List available offerings in the marketplace`))
   527  				Expect(testUI.Out).To(Say(`   create-service\s+Create a service instance`))
   528  				Expect(testUI.Out).To(Say(`   share-service\s+Share a service instance with another space`))
   529  				Expect(testUI.Out).To(Say(`   unshare-service\s+Unshare a shared service instance from a space`))
   530  				Expect(testUI.Out).To(Say(""))
   531  				Expect(testUI.Out).To(Say("ORGS:"))
   532  				Expect(testUI.Out).To(Say(`   orgs\s+List all orgs`))
   533  				Expect(testUI.Out).To(Say(`   delete-org\s+Delete an org`))
   534  				Expect(testUI.Out).To(Say(""))
   535  				Expect(testUI.Out).To(Say("SPACES:"))
   536  				Expect(testUI.Out).To(Say(`   spaces\s+List all spaces in an org`))
   537  				Expect(testUI.Out).To(Say(`   allow-space-ssh\s+Allow SSH access for the space`))
   538  				Expect(testUI.Out).To(Say(""))
   539  				Expect(testUI.Out).To(Say("DOMAINS:"))
   540  				Expect(testUI.Out).To(Say(`   domains\s+List domains in the target org`))
   541  				Expect(testUI.Out).To(Say(`   router-groups\s+List router groups`))
   542  				Expect(testUI.Out).To(Say(""))
   543  				Expect(testUI.Out).To(Say("ROUTES:"))
   544  				Expect(testUI.Out).To(Say(`   routes\s+List all routes in the current space or the current organization`))
   545  				Expect(testUI.Out).To(Say(`   unmap-route\s+Remove a url route from an app`))
   546  				Expect(testUI.Out).To(Say(""))
   547  				Expect(testUI.Out).To(Say("NETWORK POLICIES:"))
   548  				Expect(testUI.Out).To(Say(`   network-policies\s+List direct network traffic policies`))
   549  				Expect(testUI.Out).To(Say(`   add-network-policy\s+Create policy to allow direct network traffic from one app to another`))
   550  				Expect(testUI.Out).To(Say(`   remove-network-policy\s+Remove network traffic policy of an app`))
   551  				Expect(testUI.Out).To(Say(""))
   552  				Expect(testUI.Out).To(Say("BUILDPACKS:"))
   553  				Expect(testUI.Out).To(Say(`   buildpacks\s+List all buildpacks`))
   554  				Expect(testUI.Out).To(Say(`   delete-buildpack\s+Delete a buildpack`))
   555  				Expect(testUI.Out).To(Say(""))
   556  				Expect(testUI.Out).To(Say("USER ADMIN:"))
   557  				Expect(testUI.Out).To(Say(`   create-user\s+Create a new user`))
   558  				Expect(testUI.Out).To(Say(`   space-users\s+Show space users by role`))
   559  				Expect(testUI.Out).To(Say(""))
   560  				Expect(testUI.Out).To(Say("ORG ADMIN:"))
   561  				Expect(testUI.Out).To(Say(`   quotas\s+List available usage quotas`))
   562  				Expect(testUI.Out).To(Say(`   delete-quota\s+Delete a quota`))
   563  				Expect(testUI.Out).To(Say(""))
   564  				Expect(testUI.Out).To(Say("SPACE ADMIN:"))
   565  				Expect(testUI.Out).To(Say(`   space-quotas\s+List available space resource quotas`))
   566  				Expect(testUI.Out).To(Say(`   set-space-quota\s+Assign a space quota definition to a space`))
   567  				Expect(testUI.Out).To(Say(""))
   568  				Expect(testUI.Out).To(Say("SERVICE ADMIN:"))
   569  				Expect(testUI.Out).To(Say(`   service-auth-tokens\s+List service auth tokens`))
   570  				Expect(testUI.Out).To(Say(`   service-access\s+List service access settings`))
   571  				Expect(testUI.Out).To(Say(""))
   572  				Expect(testUI.Out).To(Say("SECURITY GROUP:"))
   573  				Expect(testUI.Out).To(Say(`   security-group\s+Show a single security group`))
   574  				Expect(testUI.Out).To(Say(`   staging-security-groups\s+List security groups in the staging set for applications`))
   575  				Expect(testUI.Out).To(Say(""))
   576  				Expect(testUI.Out).To(Say("ENVIRONMENT VARIABLE GROUPS:"))
   577  				Expect(testUI.Out).To(Say(`   running-environment-variable-group\s+Retrieve the contents of the running environment variable group`))
   578  				Expect(testUI.Out).To(Say("   set-running-environment-variable-group Pass parameters as JSON to create a running environment variable group"))
   579  				Expect(testUI.Out).To(Say(""))
   580  				Expect(testUI.Out).To(Say("ISOLATION SEGMENTS:"))
   581  				Expect(testUI.Out).To(Say(`   isolation-segments\s+List all isolation segments`))
   582  				Expect(testUI.Out).To(Say(`   create-isolation-segment\s+Create an isolation segment`))
   583  				Expect(testUI.Out).To(Say(`   delete-isolation-segment\s+Delete an isolation segment`))
   584  				Expect(testUI.Out).To(Say(`   enable-org-isolation\s+Entitle an organization to an isolation segment`))
   585  				Expect(testUI.Out).To(Say(`   disable-org-isolation\s+Revoke an organization's entitlement to an isolation segment`))
   586  				Expect(testUI.Out).To(Say(`   set-org-default-isolation-segment\s+Set the default isolation segment used for apps in spaces in an org`))
   587  				Expect(testUI.Out).To(Say(`   reset-org-default-isolation-segment\s+Reset the default isolation segment used for apps in spaces of an org`))
   588  				Expect(testUI.Out).To(Say("   set-space-isolation-segment"))
   589  				Expect(testUI.Out).To(Say("   reset-space-isolation-segment"))
   590  				Expect(testUI.Out).To(Say(""))
   591  				Expect(testUI.Out).To(Say("FEATURE FLAGS:"))
   592  				Expect(testUI.Out).To(Say(`   feature-flags\s+Retrieve list of feature flags with status`))
   593  				Expect(testUI.Out).To(Say("   disable-feature-flag"))
   594  				Expect(testUI.Out).To(Say(""))
   595  				Expect(testUI.Out).To(Say("ADVANCED:"))
   596  				Expect(testUI.Out).To(Say(`   curl\s+Executes a request to the targeted API endpoint`))
   597  				Expect(testUI.Out).To(Say(`   ssh-code\s+Get a one time password for ssh clients`))
   598  				Expect(testUI.Out).To(Say(""))
   599  				Expect(testUI.Out).To(Say("ADD/REMOVE PLUGIN REPOSITORY:"))
   600  				Expect(testUI.Out).To(Say(`   add-plugin-repo\s+Add a new plugin repository`))
   601  				Expect(testUI.Out).To(Say(`   repo-plugins\s+List all available plugins in specified repository or in all added repositories`))
   602  				Expect(testUI.Out).To(Say(""))
   603  				Expect(testUI.Out).To(Say("ADD/REMOVE PLUGIN:"))
   604  				Expect(testUI.Out).To(Say(`   plugins\s+List commands of installed plugins`))
   605  				Expect(testUI.Out).To(Say(`   uninstall-plugin\s+Uninstall CLI plugin`))
   606  				Expect(testUI.Out).To(Say(""))
   607  				Expect(testUI.Out).To(Say("INSTALLED PLUGIN COMMANDS:"))
   608  				Expect(testUI.Out).To(Say(`   enable-diego\s+enable Diego support for an app`))
   609  				Expect(testUI.Out).To(Say(""))
   610  				Expect(testUI.Out).To(Say("ENVIRONMENT VARIABLES:"))
   611  				Expect(testUI.Out).To(Say("   CF_COLOR=false                     Do not colorize output"))
   612  				Expect(testUI.Out).To(Say("   CF_DIAL_TIMEOUT=6                  Max wait time to establish a connection, including name resolution, in seconds"))
   613  				Expect(testUI.Out).To(Say("   CF_HOME=path/to/dir/               Override path to default config directory"))
   614  				Expect(testUI.Out).To(Say("   CF_PLUGIN_HOME=path/to/dir/        Override path to default plugin config directory"))
   615  				Expect(testUI.Out).To(Say("   CF_TRACE=true                      Print API request diagnostics to stdout"))
   616  				Expect(testUI.Out).To(Say("   CF_TRACE=path/to/trace.log         Append API request diagnostics to a log file"))
   617  				Expect(testUI.Out).To(Say("   all_proxy=proxy.example.com:8080   Specify a proxy server to enable proxying for all requests"))
   618  				Expect(testUI.Out).To(Say("   https_proxy=proxy.example.com:8080 Enable proxying for HTTP requests"))
   619  				Expect(testUI.Out).To(Say(""))
   620  				Expect(testUI.Out).To(Say("GLOBAL OPTIONS:"))
   621  				Expect(testUI.Out).To(Say("   --help, -h                         Show help"))
   622  				Expect(testUI.Out).To(Say("   -v                                 Print API request diagnostics to stdout"))
   623  				Expect(testUI.Out).To(Say(""))
   624  				Expect(testUI.Out).To(Say(`APPS \(experimental\):`))
   625  				Expect(testUI.Out).To(Say(`   v3-apps\s+List all apps in the target space`))
   626  				Expect(testUI.Out).To(Say(`   v3-create-app\s+Create a V3 App`))
   627  				Expect(testUI.Out).To(Say(`   v3-push\s+Push a new app or sync changes to an existing app`))
   628  				Expect(testUI.Out).To(Say(`   v3-scale\s+Change or view the instance count, disk space limit, and memory limit for an app`))
   629  				Expect(testUI.Out).To(Say(`   v3-delete\s+Delete a V3 App`))
   630  				Expect(testUI.Out).To(Say(`   v3-start\s+Start an app`))
   631  				Expect(testUI.Out).To(Say(`   v3-stop\s+Stop an app`))
   632  				Expect(testUI.Out).To(Say(`   v3-restart\s+Stop all instances of the app, then start them again. This causes downtime.`))
   633  				Expect(testUI.Out).To(Say(`   v3-stage\s+Create a new droplet for an app`))
   634  				Expect(testUI.Out).To(Say(`   v3-restart-app-instance\s+Terminate, then instantiate an app instance`))
   635  				Expect(testUI.Out).To(Say(`   v3-apply-manifest\s+Applies manifest properties to an application`))
   636  				Expect(testUI.Out).To(Say(`   v3-set-droplet\s+Set the droplet used to run an app`))
   637  				Expect(testUI.Out).To(Say(`   v3-env\s+Show all env variables for an app`))
   638  				Expect(testUI.Out).To(Say(`   v3-set-env\s+Set an env variable for an app`))
   639  				Expect(testUI.Out).To(Say(`   v3-unset-env\s+Remove an env variable from an app`))
   640  				Expect(testUI.Out).To(Say(`   v3-get-health-check\s+Show the type of health check performed on an app`))
   641  				Expect(testUI.Out).To(Say(`   v3-set-health-check\s+Change type of health check performed on an app's process`))
   642  				Expect(testUI.Out).To(Say(`   v3-packages\s+List packages of an app`))
   643  				Expect(testUI.Out).To(Say(`   v3-create-package\s+Uploads a V3 Package`))
   644  				Expect(testUI.Out).To(Say(`   v3-ssh\s+SSH to an application container instance`))
   645  			})
   646  
   647  			When("there are multiple installed plugins", func() {
   648  				BeforeEach(func() {
   649  					fakeConfig.PluginsReturns([]configv3.Plugin{
   650  						{
   651  							Name: "Some-other-plugin",
   652  							Commands: []configv3.PluginCommand{
   653  								{
   654  									Name:     "some-other-plugin-command",
   655  									HelpText: "does some other thing",
   656  								},
   657  							},
   658  						},
   659  						{
   660  							Name: "some-plugin",
   661  							Commands: []configv3.PluginCommand{
   662  								{
   663  									Name:     "enable",
   664  									HelpText: "enable command",
   665  								},
   666  								{
   667  									Name:     "disable",
   668  									HelpText: "disable command",
   669  								},
   670  								{
   671  									Name:     "some-other-command",
   672  									HelpText: "does something",
   673  								},
   674  							},
   675  						},
   676  						{
   677  							Name: "the-last-plugin",
   678  							Commands: []configv3.PluginCommand{
   679  								{
   680  									Name:     "last-plugin-command",
   681  									HelpText: "does the last thing",
   682  								},
   683  							},
   684  						},
   685  					})
   686  				})
   687  
   688  				It("returns the plugin commands organized by plugin and sorted in alphabetical order", func() {
   689  					err := cmd.Execute(nil)
   690  					Expect(err).ToNot(HaveOccurred())
   691  
   692  					Expect(testUI.Out).To(Say(`INSTALLED PLUGIN COMMANDS:.*
   693  \s+some-other-plugin-command\s+does some other thing.*
   694  \s+disable\s+disable command.*
   695  \s+enable\s+enable command.*
   696  \s+some-other-command\s+does something.*
   697  \s+last-plugin-command\s+does the last thing`))
   698  				})
   699  			})
   700  		})
   701  	})
   702  })