本文整理匯總了Golang中code/cloudfoundry/org/cli/cf/flags.FlagContext.Float64方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.Float64方法的具體用法?Golang FlagContext.Float64怎麽用?Golang FlagContext.Float64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/cli/cf/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.Float64方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
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)))
示例2:
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"))
})