Example #1
0
func createCommandFactory() command_factory.Factory {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	pluginConfig := &testPluginConfig.FakePluginConfiguration{}

	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo, fakeUI),
		"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
		"uaa":              net.NewUAAGateway(configRepo, fakeUI),
	})

	return command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig)
}
Example #2
0
File: main.go Project: nttlabs/cli
func main() {
	defer handlePanics(deps.teePrinter)
	defer deps.configRepo.Close()

	cmdFactory := command_factory.NewFactory(deps.termUI, deps.configRepo, deps.manifestRepo, deps.apiRepoLocator, deps.pluginConfig)
	requirementsFactory := requirements.NewFactory(deps.termUI, deps.configRepo, deps.apiRepoLocator)
	cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, deps.termUI)

	theApp := app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
	//command `cf` without argument
	if len(os.Args) == 1 || os.Args[1] == "help" {
		theApp.Run(os.Args)
	} else if cmdFactory.CheckIfCoreCmdExists(os.Args[1]) {
		callCoreCommand(os.Args[0:], theApp)
	} else {
		// run each plugin and find the method/
		// run method if exist
		ran := rpc.RunMethodIfExists(theApp, os.Args[1:], deps.teePrinter, deps.teePrinter)
		if !ran {
			theApp.Run(os.Args)
		}
	}
}
Example #3
0
func findCommand(cmdName string) (cmd cli.Command) {
	fakeUI := &testterm.FakeUI{}
	configRepo := testconfig.NewRepository()
	pluginConfig := &testPluginConfig.FakePluginConfiguration{}
	manifestRepo := manifest.NewManifestDiskRepository()
	apiRepoLocator := api.NewRepositoryLocator(configRepo, map[string]net.Gateway{
		"auth":             net.NewUAAGateway(configRepo, fakeUI),
		"cloud-controller": net.NewCloudControllerGateway(configRepo, time.Now, fakeUI),
		"uaa":              net.NewUAAGateway(configRepo, fakeUI),
	})

	cmdFactory := command_factory.NewFactory(fakeUI, configRepo, manifestRepo, apiRepoLocator, pluginConfig)
	requirementsFactory := &testreq.FakeReqFactory{}
	cmdRunner := command_runner.NewRunner(cmdFactory, requirementsFactory, fakeUI)
	myApp := app.NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)

	for _, cmd := range myApp.Commands {
		if cmd.Name == cmdName {
			return cmd
		}
	}
	panic(fmt.Sprintf("command %s does not exist", cmdName))
	return
}
Example #4
0
		cmdRunner *FakeRunner
	)

	JustBeforeEach(func() {
		ui := &testterm.FakeUI{}
		config := testconfig.NewRepository()
		pluginConfig := &testPluginConfig.FakePluginConfiguration{}
		manifestRepo := &testmanifest.FakeManifestRepository{}

		repoLocator := api.NewRepositoryLocator(config, map[string]net.Gateway{
			"auth":             net.NewUAAGateway(config, ui),
			"cloud-controller": net.NewCloudControllerGateway(config, time.Now, &testterm.FakeUI{}),
			"uaa":              net.NewUAAGateway(config, ui),
		})

		cmdFactory := command_factory.NewFactory(ui, config, manifestRepo, repoLocator, pluginConfig)
		cmdRunner = &FakeRunner{cmdFactory: cmdFactory}
		app = NewApp(cmdRunner, cmdFactory.CommandMetadatas()...)
	})

	Describe("trace file integration", func() {
		var (
			output *bytes.Buffer
		)

		BeforeEach(func() {
			output = bytes.NewBuffer(make([]byte, 1024))
			trace.SetStdout(output)
			trace.EnableTrace()
		})