Exemplo n.º 1
0
func main() {
	logger := newLogger()
	defer logger.HandlePanic("Main")
	fileSystem := boshsys.NewOsFileSystemWithStrictTempRoot(logger)
	workspaceRootPath := path.Join(os.Getenv("HOME"), ".bosh_init")
	ui := biui.NewConsoleUI(logger)

	timeService := clock.NewClock()

	cmdFactory := bicmd.NewFactory(
		fileSystem,
		ui,
		timeService,
		logger,
		boshuuid.NewGenerator(),
		workspaceRootPath,
	)

	cmdRunner := bicmd.NewRunner(cmdFactory)
	stage := biui.NewStage(ui, timeService, logger)
	err := cmdRunner.Run(stage, os.Args[1:]...)
	if err != nil {
		displayHelpFunc := func() {
			if strings.Contains(err.Error(), "Invalid usage") {
				ui.ErrorLinef("")
				helpErr := cmdRunner.Run(stage, append([]string{"help"}, os.Args[1:]...)...)
				if helpErr != nil {
					logger.Error(mainLogTag, "Couldn't print help: %s", helpErr.Error())
				}
			}
		}
		fail(err, ui, logger, displayHelpFunc)
	}
}
Exemplo n.º 2
0
var _ = Describe("Runner", func() {
	var (
		runner      *bicmd.Runner
		factory     *fakebicmd.FakeFactory
		fakeCommand *fakebicmd.FakeCommand
		fakeStage   *fakebiui.FakeStage
	)

	BeforeEach(func() {
		fakeCommand = fakebicmd.NewFakeCommand("fake-command-name", bicmd.Meta{})
		factory = &fakebicmd.FakeFactory{PresetCommand: fakeCommand}
		fakeStage = fakebiui.NewFakeStage()
	})

	JustBeforeEach(func() {
		runner = bicmd.NewRunner(factory)
	})

	Context("Run", func() {
		Context("valid args", func() {
			It("extracts command name from the arguments", func() {
				err := runner.Run(fakeStage, "fake-command-name", "/fake/manifest_path")
				Expect(err).ToNot(HaveOccurred())
				Expect(factory.CommandName).To(Equal("fake-command-name"))
			})

			It("creates and run a non nil Command with remaining args", func() {
				err := runner.Run(fakeStage, "fake-command-name", "/fake/manifest_path")
				Expect(err).ToNot(HaveOccurred())
				Expect(factory.CommandName).To(Equal("fake-command-name"))
				Expect(factory.PresetCommand).ToNot(BeNil())