Example #1
0
File: app.go Project: phanle/s3cli
func (app app) Run(args []string) (err error) {
	args = args[1:]

	configPath, args, err := getConfigPath(args)
	if err != nil {
		return
	}

	s3Client, err := s3cliclient.GetS3Client(configPath)
	if err != nil {
		return
	}

	cmdFactory := s3clicmd.NewFactory(s3Client)
	cmdRunner := s3clicmd.NewRunner(cmdFactory)

	if len(args) < 1 {
		err = errors.New("Command missing")
		return
	}

	cmdName := args[0]
	cmdArgs := args[1:]
	err = cmdRunner.Run(cmdName, cmdArgs)
	return
}
package cmd_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	s3clicmd "s3cli/cmd"
	fakecmd "s3cli/cmd/fakes"
)

var _ = Describe("runner", func() {
	Describe("Run", func() {
		It("run specified command with given arguments", func() {
			fakeFactory := &fakecmd.FakeFactory{CreatedCmd: &fakecmd.FakeCmd{}}
			runner := s3clicmd.NewRunner(fakeFactory)

			err := runner.Run("some-cmd", []string{"param1", "param2"})
			Expect(err).ToNot(HaveOccurred())
			Expect(fakeFactory.CreatedCmdName).To(Equal("some-cmd"))
			Expect(fakeFactory.CreatedCmd.RunArgs).To(Equal([]string{"param1", "param2"}))
		})
	})
})