示例#1
0
func NewCliApp() *cli.App {
	config := config.New(persister.NewFilePersister(config_helpers.ConfigFileLocation(ltcConfigRoot())))

	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, os.Interrupt)
	exitHandler := exit_handler.New(signalChan, os.Exit)
	go exitHandler.Run()

	targetVerifier := target_verifier.New(receptor_client_factory.MakeReceptorClient)
	app := cli_app_factory.MakeCliApp(latticeVersion, ltcConfigRoot(), exitHandler, config, logger(), targetVerifier, os.Stdout)
	return app
}
示例#2
0
func NewCliApp() *cli.App {
	config := config.New(persister.NewFilePersister(config_helpers.ConfigFileLocation(ltcConfigRoot())))

	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, os.Interrupt)
	exitHandler := exit_handler.New(signalChan, os.Exit)
	go exitHandler.Run()

	receptorClientCreator := receptor_client.ProxyAwareCreator{}

	return cli_app_factory.MakeCliApp(
		diegoVersion,
		latticeVersion,
		ltcConfigRoot(),
		exitHandler,
		config,
		logger(),
		receptorClientCreator,
		target_verifier.New(receptorClientCreator),
		os.Stdout,
	)
}
示例#3
0
func NewCliApp() *cli.App {
	config := config.New(persister.NewFilePersister(config_helpers.ConfigFileLocation(ltcConfigRoot())))

	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, os.Interrupt)
	exitHandler := exit_handler.New(signalChan, os.Exit)
	go exitHandler.Run()

	targetVerifier := target_verifier.New(func(target string) receptor.Client {
		return receptor.NewClient(target)
	})

	return cli_app_factory.MakeCliApp(
		diegoVersion,
		latticeVersion,
		ltcConfigRoot(),
		exitHandler,
		config,
		logger(),
		targetVerifier,
		os.Stdout,
	)
}
示例#4
0
	BeforeEach(func() {
		fakeTargetVerifier = &fake_target_verifier.FakeTargetVerifier{}
		fakeExitHandler = new(fake_exit_handler.FakeExitHandler)
		memPersister := persister.NewMemPersister()
		outputBuffer = gbytes.NewBuffer()
		terminalUI = terminal.NewUI(nil, outputBuffer, nil)
		cliConfig = config.New(memPersister)
		latticeVersion, diegoVersion = "v0.2.Test", "0.12345.0"
	})

	JustBeforeEach(func() {
		cliApp = cli_app_factory.MakeCliApp(
			diegoVersion,
			latticeVersion,
			"~/",
			fakeExitHandler,
			cliConfig,
			lager.NewLogger("test"),
			fakeTargetVerifier,
			terminalUI,
		)
	})

	Describe("MakeCliApp", func() {
		It("makes an app", func() {
			Expect(cliApp).ToNot(BeNil())
			Expect(cliApp.Name).To(Equal("ltc"))
			Expect(cliApp.Author).To(Equal("Pivotal"))
			Expect(cliApp.Version).To(Equal("v0.2.Test (diego 0.12345.0)"))
			Expect(cliApp.Email).To(Equal("*****@*****.**"))
			Expect(cliApp.Usage).To(Equal(cli_app_factory.LtcUsage))
			Expect(cliApp.Commands).NotTo(BeEmpty())
	subCommandTemplate := `NAME:
   {{.Name}} - {{.Usage}}
USAGE:
   {{.Name}} command{{if .Flags}} [command options]{{end}} [arguments...]
`
	BeforeEach(func() {
		outputBuffer = gbytes.NewBuffer()

		fakeReceptorClientCreator = &fake_receptor_client_creator.FakeCreator{}

		cliApp = cli_app_factory.MakeCliApp(
			"",
			"",
			"~/",
			nil,
			config.New(persister.NewMemPersister()),
			nil,
			fakeReceptorClientCreator,
			nil,
			terminal.NewUI(nil, outputBuffer, nil),
		)
	})

	Describe("ShowHelp", func() {

		It("shows help for all commands", func() {
			Expect(cliApp.Commands).NotTo(BeEmpty())

			cli_app_factory.ShowHelp(outputBuffer, dummyTemplate, cliApp)

			outputBytes, err := ioutil.ReadAll(outputBuffer)
		outputBuffer       *gbytes.Buffer
		terminalUI         terminal.UI
		cliConfig          *config.Config
		cliApp             *cli.App
	)

	BeforeEach(func() {
		fakeTargetVerifier = &fake_target_verifier.FakeTargetVerifier{}
		outputBuffer = gbytes.NewBuffer()
		terminalUI = terminal.NewUI(nil, outputBuffer, nil)
		cliConfig = config.New(persister.NewMemPersister())
		cliApp = cli_app_factory.MakeCliApp(
			"",
			"~/",
			nil,
			cliConfig,
			nil,
			fakeTargetVerifier,
			terminalUI,
		)
	})

	Describe("MatchArgAndFlags", func() {
		It("Checks for badflag", func() {
			cliAppArgs := []string{"ltc", "create", "--badflag"}
			flags := main.GetCommandFlags(cliApp, cliAppArgs[1])
			badFlags := main.MatchArgAndFlags(flags, cliAppArgs[2:])

			Expect(badFlags).To(Equal("Unknown flag \"--badflag\""))
		})