本文整理匯總了Golang中github.com/simonleung8/flags.FlagContext.StringSlice方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagContext.StringSlice方法的具體用法?Golang FlagContext.StringSlice怎麽用?Golang FlagContext.StringSlice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/simonleung8/flags.FlagContext
的用法示例。
在下文中一共展示了FlagContext.StringSlice方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 = REQUEST_TTY_YES
}
if fc.IsSet("tt") && fc.Bool("tt") {
sshOptions.TerminalRequest = REQUEST_TTY_FORCE
}
if fc.Bool("T") {
sshOptions.TerminalRequest = REQUEST_TTY_NO
}
return sshOptions, nil
}
示例2: Execute
func (cmd *Curl) Execute(c flags.FlagContext) {
path := c.Args()[0]
method := c.String("X")
headers := c.StringSlice("H")
body := c.String("d")
verbose := c.Bool("v")
reqHeader := strings.Join(headers, "\n")
if verbose {
trace.EnableTrace()
}
responseHeader, responseBody, apiErr := cmd.curlRepo.Request(method, path, reqHeader, body)
if apiErr != nil {
cmd.ui.Failed(T("Error creating request:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()}))
}
if verbose {
return
}
if c.Bool("i") {
cmd.ui.Say(responseHeader)
}
if c.String("output") != "" {
err := cmd.writeToFile(responseBody, c.String("output"))
if err != nil {
cmd.ui.Failed(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
}
示例3:
Ω(fc.Float64("i")).To(Equal(float64(0)))
fc.NewFloat64FlagWithDefault("i", "i2", "setting new flag", 5.5)
fc.Parse()
Ω(fc.IsSet("i")).To(BeTrue())
Ω(fc.IsSet("i2")).To(BeTrue())
Ω(fc.Float64("i")).To(Equal(5.5))
Ω(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")
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.StringSlice("s")).To(Equal([]string{}))
fc.NewStringSliceFlag("s", "s2", "setting new StringSlice flag")
fc.Parse("-s", "5", "-s", "6")
Ω(fc.IsSet("s")).To(BeTrue())
Ω(fc.IsSet("s2")).To(BeTrue())
Ω(fc.StringSlice("s")).To(Equal([]string{"5", "6"}))
Ω(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()
Ω(fc.IsSet("s")).To(BeFalse())
Ω(fc.StringSlice("s")).To(Equal([]string{}))