本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.StringFlag類的典型用法代碼示例。如果您正苦於以下問題:Golang StringFlag類的具體用法?Golang StringFlag怎麽用?Golang StringFlag使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StringFlag類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewCmdStartBuild
// NewCmdStartBuild implements the OpenShift cli start-build command
func NewCmdStartBuild(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
webhooks := util.StringFlag{}
webhooks.Default("none")
cmd := &cobra.Command{
Use: "start-build (BUILDCONFIG | --from-build=BUILD)",
Short: "Starts a new build",
Long: startBuildLong,
Example: fmt.Sprintf(startBuildExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
err := RunStartBuild(f, out, cmd, args, webhooks)
cmdutil.CheckErr(err)
},
}
cmd.Flags().String("from-build", "", "Specify the name of a build which should be re-run")
cmd.Flags().Bool("follow", false, "Start a build and watch its logs until it completes or fails")
cmd.Flags().Var(&webhooks, "list-webhooks", "List the webhooks for the specified BuildConfig or build; accepts 'all', 'generic', or 'github'")
cmd.Flags().String("from-webhook", "", "Specify a webhook URL for an existing BuildConfign to trigger")
cmd.Flags().String("git-post-receive", "", "The contents of the post-receive hook to trigger a build")
cmd.Flags().String("git-repository", "", "The path to the git repository for post-receive; defaults to the current directory")
return cmd
}
示例2: RunStartBuild
// RunStartBuild contains all the necessary functionality for the OpenShift cli start-build command
func RunStartBuild(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, webhooks util.StringFlag) error {
webhook := cmdutil.GetFlagString(cmd, "from-webhook")
buildName := cmdutil.GetFlagString(cmd, "from-build")
follow := cmdutil.GetFlagBool(cmd, "follow")
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 {
return cmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments or '--from-build'")
}
path := cmdutil.GetFlagString(cmd, "git-repository")
postReceivePath := cmdutil.GetFlagString(cmd, "git-post-receive")
repo := git.NewRepository()
return RunStartBuildWebHook(f, out, webhook, path, postReceivePath, repo)
case len(args) != 1 && len(buildName) == 0:
return cmdutil.UsageError(cmd, "Must pass a name of a BuildConfig or specify build name with '--from-build' flag")
}
name := buildName
isBuild := true
if len(name) == 0 {
name = args[0]
isBuild = false
}
if webhooks.Provided() {
return RunListBuildWebHooks(f, out, cmd.Out(), name, isBuild, webhooks.String())
}
client, _, err := f.Clients()
if err != nil {
return err
}
namespace, err := f.DefaultNamespace()
if err != nil {
return err
}
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{Name: name},
}
var newBuild *buildapi.Build
if isBuild {
if newBuild, err = client.Builds(namespace).Clone(request); err != nil {
return err
}
} else {
if newBuild, err = client.BuildConfigs(namespace).Instantiate(request); err != nil {
return err
}
}
fmt.Fprintf(out, "%s\n", newBuild.Name)
if follow {
opts := buildapi.BuildLogOptions{
Follow: true,
NoWait: false,
}
rd, err := client.BuildLogs(namespace).Get(newBuild.Name, opts).Stream()
if err != nil {
return fmt.Errorf("error getting logs: %v", err)
}
defer rd.Close()
_, err = io.Copy(out, rd)
if err != nil {
return fmt.Errorf("error streaming logs: %v", err)
}
}
return nil
}