func (cmd targetCommand) Execute(args []string) (int, error) {
	cmd.printer.Printf("Executing %s comamnd: args: %#v, options: %#v", cmd.Name(), args, cmd.options)

	validate, err := cmd.Validate()
	if validate == false && err == nil {
		return 1, errors.New("bmp target validation error")
	} else if validate == false && err != nil {
		return 1, err
	}

	configInfo, err := common.CreateConfig(cmd.bmpClient.ConfigPath())
	if err != nil {
		return 1, err
	}

	configInfo.TargetUrl = cmd.options.Target

	c := config.NewConfig(cmd.bmpClient.ConfigPath())
	err = c.SaveConfig(configInfo)
	if err != nil {
		return 1, err
	}

	return 0, nil
}
func (cmd loginCommand) Execute(args []string) (int, error) {
	cmd.printer.Printf("Executing %s comamnd: args: %#v, options: %#v", cmd.Name(), args, cmd.options)

	loginResponse, err := cmd.bmpClient.Login(cmd.options.Username, cmd.options.Password)
	if err != nil {
		return loginResponse.Status, err
	}

	if loginResponse.Status != 200 {
		return loginResponse.Status, nil
	}

	c := config.NewConfig(cmd.bmpClient.ConfigPath())
	configInfo, err := c.LoadConfig()
	if err != nil {
		return 1, err
	}

	configInfo.Username = cmd.options.Username
	configInfo.Password = cmd.options.Password

	err = c.SaveConfig(configInfo)
	if err != nil {
		return 1, err
	}

	cmd.ui.PrintfInfo("Login Successful!\n")
	return 0, nil
}
func createTmpConfig(tmpDir string, configInfo config.ConfigInfo) string {
	tmpFile, err := ioutil.TempFile(tmpDir, ".bmp_config")
	Expect(err).ToNot(HaveOccurred())

	c := config.NewConfig(tmpFile.Name())
	Expect(err).ToNot(HaveOccurred())

	err = c.SaveConfig(configInfo)
	Expect(err).ToNot(HaveOccurred())

	return tmpFile.Name()
}
func CreateBmpClient() (clients.BmpClient, error) {
	currentUser, err := user.Current()
	if err != nil {
		return nil, err
	}

	c := config.NewConfig(filepath.Join(currentUser.HomeDir, config.CONFIG_FILE_NAME))
	configInfo, err := c.LoadConfig()
	if err != nil {
		return nil, err
	}

	return clients.NewBmpClient(configInfo.Username, configInfo.Password, configInfo.TargetUrl, nil, c.Path()), nil
}
func CreateConfig(pathToConfig string) (config.ConfigInfo, error) {
	config := config.NewConfig(pathToConfig)
	return config.LoadConfig()
}
			It("fails to create a BMP client", func() {
				_, err = common.CreateBmpClient()
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Context("#CreateConfig", func() {
		BeforeEach(func() {
			tmpFile, err := ioutil.TempFile(tmpDir, ".bmp_config")
			Expect(err).ToNot(HaveOccurred())

			tmpFileName = tmpFile.Name()

			c := config.NewConfig(tmpFileName)
			err = c.SaveConfig(config.ConfigInfo{})
			Expect(err).ToNot(HaveOccurred())

			configInfo, err := c.LoadConfig()
			Expect(err).ToNot(HaveOccurred())

			Expect(configInfo.Username).To(Equal(""))
			Expect(configInfo.Password).To(Equal(""))
			Expect(configInfo.TargetUrl).To(Equal(""))
		})

		It("creates config with data", func() {
			c := config.NewConfig(tmpFileName)
			Expect(err).ToNot(HaveOccurred())
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	config "github.com/cloudfoundry-community/bosh-softlayer-tools/config"
)

var _ = Describe("config", func() {
	var (
		c                       config.Config
		err                     error
		tmpDirName, tmpFileName string
	)

	BeforeEach(func() {
		c = config.NewConfig("fake-path")
	})

	Describe("#Path", func() {
		Context("when a path is path to config", func() {
			It("returns the fake-path config path", func() {
				Expect(c.Path()).To(Equal("fake-path"))
			})
		})

		Context("when no path is set", func() {
			BeforeEach(func() {
				c = config.NewConfig("")
			})

			It("returns the default config path", func() {
				options.Target = "..."
				badCmd2 = bmp.NewTargetCommand(options, fakeBmpClient)
			})

			It("returns false on validation", func() {
				validate, err := badCmd1.Validate()
				Expect(validate).To(BeFalse())
				Expect(err).To(HaveOccurred())

				validate, err = badCmd2.Validate()
				Expect(validate).To(BeFalse())
				Expect(err).To(HaveOccurred())
			})
		})
	})

	Describe("#Execute", func() {
		It("executes a good TargetCommand", func() {
			rc, err := cmd.Execute(args)
			Expect(rc).To(Equal(0))
			Expect(err).ToNot(HaveOccurred())

			c := config.NewConfig(fakeBmpClient.ConfigPath())
			configInfo, err := c.LoadConfig()
			Expect(err).ToNot(HaveOccurred())
			Expect(configInfo.TargetUrl).To(Equal("http://fake.url"))
		})
	})
})