本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/flags.FlagContext.StringSlice方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.StringSlice方法的具體用法?Golang FlagContext.StringSlice怎麽用?Golang FlagContext.StringSlice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.StringSlice方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewSSHOptions
func NewSSHOptions(fc flags.FlagContext) (*SSHOptions, error) {
sshOptions := &SSHOptions{}
sshOptions.AppName = fc.Args()[0]
sshOptions.Index = uint(fc.Int("i"))
sshOptions.SkipHostValidation = fc.Bool("k")
sshOptions.SkipRemoteExecution = fc.Bool("N")
sshOptions.Command = fc.StringSlice("c")
if fc.IsSet("L") {
for _, arg := range fc.StringSlice("L") {
forwardSpec, err := sshOptions.parseLocalForwardingSpec(arg)
if err != nil {
return sshOptions, err
}
sshOptions.ForwardSpecs = append(sshOptions.ForwardSpecs, *forwardSpec)
}
}
if fc.IsSet("t") && fc.Bool("t") {
sshOptions.TerminalRequest = RequestTTYYes
}
if fc.IsSet("tt") && fc.Bool("tt") {
sshOptions.TerminalRequest = RequestTTYForce
}
if fc.Bool("T") {
sshOptions.TerminalRequest = RequestTTYNo
}
return sshOptions, nil
}
示例2: Execute
func (cmd *Curl) Execute(c flags.FlagContext) error {
path := c.Args()[0]
headers := c.StringSlice("H")
var method string
var body string
if c.IsSet("d") {
method = "POST"
jsonBytes, err := util.GetContentsFromOptionalFlagValue(c.String("d"))
if err != nil {
return err
}
body = string(jsonBytes)
}
if c.IsSet("X") {
method = c.String("X")
}
reqHeader := strings.Join(headers, "\n")
responseHeader, responseBody, apiErr := cmd.curlRepo.Request(method, path, reqHeader, body)
if apiErr != nil {
return errors.New(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
}
if trace.LoggingToStdout && !cmd.pluginCall {
return nil
}
if c.Bool("i") {
cmd.ui.Say(responseHeader)
}
if c.String("output") != "" {
err := cmd.writeToFile(responseBody, c.String("output"))
if err != nil {
return errors.New(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": err}))
}
} else {
if strings.Contains(responseHeader, "application/json") {
buffer := bytes.Buffer{}
err := json.Indent(&buffer, []byte(responseBody), "", " ")
if err == nil {
responseBody = buffer.String()
}
}
cmd.ui.Say(responseBody)
}
return nil
}
示例3:
Expect(fc.Float64("i")).To(Equal(float64(0)))
fc.NewFloat64FlagWithDefault("i", "i2", "setting new flag", 5.5)
fc.Parse()
Expect(fc.IsSet("i")).To(BeTrue())
Expect(fc.IsSet("i2")).To(BeTrue())
Expect(fc.Float64("i")).To(Equal(5.5))
Expect(fc.Float64("i2")).To(Equal(5.5))
})
})
Describe("NewStringSliceFlag()", func() {
It("init the flag context with a new StringSlice flagset", func() {
fc.Parse("-s", "5", "-s", "6")
Expect(fc.IsSet("s")).To(BeFalse())
Expect(fc.StringSlice("s")).To(Equal([]string{}))
fc.NewStringSliceFlag("s", "s2", "setting new StringSlice flag")
fc.Parse("-s", "5", "-s", "6")
Expect(fc.IsSet("s")).To(BeTrue())
Expect(fc.IsSet("s2")).To(BeTrue())
Expect(fc.StringSlice("s")).To(Equal([]string{"5", "6"}))
Expect(fc.StringSlice("s2")).To(Equal([]string{"5", "6"}))
})
})
Describe("NewStringSliceFlagWithDefault()", func() {
It("init the flag context with a new StringSlice flagset with default value", func() {
fc.Parse()
Expect(fc.IsSet("s")).To(BeFalse())
Expect(fc.StringSlice("s")).To(Equal([]string{}))
示例4:
Expect(fCtx.Bool("non-exisit-flag")).To(Equal(false))
})
It("sets String(<flag>) to return provided value when a string flag is provided", func() {
err := fCtx.Parse("--skip", "-name", "doe")
Expect(err).NotTo(HaveOccurred())
Expect(fCtx.String("name")).To(Equal("doe"))
Ω(fCtx.Bool("skip")).To(Equal(true), "skip should be true")
})
It("sets StringSlice(<flag>) to return provided value when a stringSlice flag is provided", func() {
err := fCtx.Parse("-slice", "value1", "-slice", "value2")
Expect(err).NotTo(HaveOccurred())
Ω(fCtx.StringSlice("slice")[0]).To(Equal("value1"), "slice[0] should be 'value1'")
Ω(fCtx.StringSlice("slice")[1]).To(Equal("value2"), "slice[1] should be 'value2'")
})
It("errors when a non-boolean flag is provided without a value", func() {
err := fCtx.Parse("-name")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("No value provided for flag"))
Expect(fCtx.String("name")).To(Equal(""))
})
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))