Exemplo n.º 1
0
			Expect(fc.Int("i")).To(Equal(0))

			fc.NewIntFlagWithDefault("i", "i2", "setting new int flag", 10)
			fc.Parse()
			Expect(fc.IsSet("i")).To(BeTrue())
			Expect(fc.IsSet("i2")).To(BeTrue())
			Expect(fc.Int("i")).To(Equal(10))
			Expect(fc.Int("i2")).To(Equal(10))
		})
	})

	Describe("NewFloat64Flag()", func() {
		It("init the flag context with a new float64 flagset", func() {
			fc.Parse("-f", "5.5")
			Expect(fc.IsSet("f")).To(BeFalse())
			Expect(fc.Float64("f")).To(Equal(float64(0)))

			fc.NewFloat64Flag("f", "f2", "setting new flag")
			fc.Parse("-f", "5.5")
			Expect(fc.IsSet("f")).To(BeTrue())
			Expect(fc.IsSet("f2")).To(BeTrue())
			Expect(fc.Float64("f")).To(Equal(5.5))
			Expect(fc.Float64("f2")).To(Equal(5.5))
		})
	})

	Describe("NewFloat64FlagWithDefault()", func() {
		It("init the flag context with a new Float64 flagset with default value", func() {
			fc.Parse()
			Expect(fc.IsSet("i")).To(BeFalse())
			Expect(fc.Float64("i")).To(Equal(float64(0)))
Exemplo n.º 2
0
			It("sets Int(<flag>) to return provided value when a int flag is provided", func() {
				err := fCtx.Parse("--instance", "10")
				Expect(err).NotTo(HaveOccurred())

				Expect(fCtx.Int("instance")).To(Equal(10))
				Expect(fCtx.IsSet("instance")).To(Equal(true))

				Expect(fCtx.Int("non-exist-flag")).To(Equal(0))
				Expect(fCtx.IsSet("non-exist-flag")).To(Equal(false))
			})

			It("sets Float64(<flag>) to return provided value when a float64 flag is provided", func() {
				err := fCtx.Parse("-float", "10.5")
				Expect(err).NotTo(HaveOccurred())

				Expect(fCtx.Float64("float")).To(Equal(10.5))
				Expect(fCtx.IsSet("float")).To(Equal(true))

				Expect(fCtx.Float64("non-exist-flag")).To(Equal(float64(0)))
				Expect(fCtx.IsSet("non-exist-flag")).To(Equal(false))
			})

			It("returns any non-flag arguments in Args()", func() {
				err := fCtx.Parse("Arg-1", "--instance", "10", "--skip", "Arg-2")
				Expect(err).NotTo(HaveOccurred())

				Expect(len(fCtx.Args())).To(Equal(2))
				Expect(fCtx.Args()[0]).To(Equal("Arg-1"))
				Expect(fCtx.Args()[1]).To(Equal("Arg-2"))
			})