本文整理汇总了Golang中github.com/openshift/origin/pkg/config/cmd.NewPrintNameOrErrorAfterIndent函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPrintNameOrErrorAfterIndent函数的具体用法?Golang NewPrintNameOrErrorAfterIndent怎么用?Golang NewPrintNameOrErrorAfterIndent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPrintNameOrErrorAfterIndent函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunNewApplication
// RunNewApplication contains all the necessary functionality for the OpenShift cli new-app command
func RunNewApplication(fullName string, f *clientcmd.Factory, out io.Writer, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
output := kcmdutil.GetFlagString(c, "output")
shortOutput := output == "name"
if err := setupAppConfig(f, out, c, args, config); err != nil {
return err
}
if config.Querying() {
result, err := config.RunQuery()
if err != nil {
return handleRunError(c, err, fullName)
}
if len(output) != 0 {
result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items)
if err != nil {
return err
}
return f.Factory.PrintObject(c, result.List, out)
}
return printHumanReadableQueryResult(result, out, fullName)
}
if err := setAppConfigLabels(c, config); err != nil {
return err
}
result, err := config.Run()
if err := handleRunError(c, err, fullName); err != nil {
return err
}
if len(config.Labels) == 0 && len(result.Name) > 0 {
config.Labels = map[string]string{"app": result.Name}
}
if err := setLabels(config.Labels, result); err != nil {
return err
}
if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewApp}, result); err != nil {
return err
}
indent := " "
switch {
case shortOutput:
indent = ""
case len(output) != 0:
result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items)
if err != nil {
return err
}
return f.Factory.PrintObject(c, result.List, out)
case !result.GeneratedJobs:
if len(config.Labels) > 0 {
fmt.Fprintf(out, "--> Creating resources with label %s ...\n", labels.SelectorFromSet(config.Labels).String())
} else {
fmt.Fprintf(out, "--> Creating resources ...\n")
}
}
if config.DryRun {
fmt.Fprintf(out, "--> Success (DRY RUN)\n")
return nil
}
mapper, _ := f.Object()
var afterFn configcmd.AfterFunc
switch {
// only print success if we don't have installables
case !result.GeneratedJobs:
afterFn = configcmd.NewPrintNameOrErrorAfterIndent(mapper, shortOutput, "created", out, c.Out(), indent)
default:
afterFn = configcmd.NewPrintErrorAfter(mapper, c.Out())
afterFn = configcmd.HaltOnError(afterFn)
}
if err := createObjects(f, afterFn, result); err != nil {
return err
}
if !shortOutput && !result.GeneratedJobs {
fmt.Fprintf(out, "--> Success\n")
}
hasMissingRepo := false
installing := []*kapi.Pod{}
for _, item := range result.List.Items {
switch t := item.(type) {
case *kapi.Pod:
if t.Annotations[newcmd.GeneratedForJob] == "true" {
installing = append(installing, t)
}
case *buildapi.BuildConfig:
triggered := false
for _, trigger := range t.Spec.Triggers {
switch trigger.Type {
//.........这里部分代码省略.........
示例2: Run
// Run contains all the necessary functionality for the OpenShift cli new-app command
func (o *NewAppOptions) Run() error {
config := o.Config
out := o.Out
output := o.Output
shortOutput := output == "name"
if config.Querying() {
result, err := config.RunQuery()
if err != nil {
return handleRunError(err, o.CommandName, o.CommandPath)
}
if len(output) != 0 {
return o.PrintObject(result.List)
}
return printHumanReadableQueryResult(result, out, o.CommandName)
}
result, err := config.Run()
if err := handleRunError(err, o.CommandName, o.CommandPath); err != nil {
return err
}
// if the user has set the "app" label explicitly on their objects in the template,
// we should not return a failure when we can't set it ourselves.
ignoreLabelFailure := false
if len(config.Labels) == 0 && len(result.Name) > 0 {
config.Labels = map[string]string{"app": result.Name}
ignoreLabelFailure = true
}
if err := setLabels(config.Labels, result, ignoreLabelFailure); err != nil {
return err
}
if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewApp}, result); err != nil {
return err
}
indent := " "
switch {
case shortOutput:
indent = ""
case len(output) != 0:
return o.PrintObject(result.List)
case !result.GeneratedJobs:
if len(config.Labels) > 0 {
fmt.Fprintf(out, "--> Creating resources with label %s ...\n", labels.SelectorFromSet(config.Labels).String())
} else {
fmt.Fprintf(out, "--> Creating resources ...\n")
}
}
if config.DryRun {
fmt.Fprintf(out, "--> Success (DRY RUN)\n")
return nil
}
var afterFn configcmd.AfterFunc
switch {
// only print success if we don't have installables
case !result.GeneratedJobs:
afterFn = configcmd.NewPrintNameOrErrorAfterIndent(config.Mapper, shortOutput, "created", out, config.ErrOut, indent)
default:
afterFn = configcmd.NewPrintErrorAfter(config.Mapper, config.ErrOut)
afterFn = configcmd.HaltOnError(afterFn)
}
if err := createObjects(config, afterFn, result); err != nil {
return err
}
if !shortOutput && !result.GeneratedJobs {
fmt.Fprintf(out, "--> Success\n")
}
hasMissingRepo := false
installing := []*kapi.Pod{}
for _, item := range result.List.Items {
switch t := item.(type) {
case *kapi.Pod:
if t.Annotations[newcmd.GeneratedForJob] == "true" {
installing = append(installing, t)
}
case *buildapi.BuildConfig:
triggered := false
for _, trigger := range t.Spec.Triggers {
switch trigger.Type {
case buildapi.ImageChangeBuildTriggerType, buildapi.ConfigChangeBuildTriggerType:
triggered = true
break
}
}
if triggered {
fmt.Fprintf(out, "%sBuild scheduled, use 'oc logs -f bc/%s' to track its progress.\n", indent, t.Name)
} else {
fmt.Fprintf(out, "%sUse 'oc start-build %s' to start a build.\n", indent, t.Name)
}
case *imageapi.ImageStream:
//.........这里部分代码省略.........
示例3: RunNewBuild
// RunNewBuild contains all the necessary functionality for the OpenShift cli new-build command
func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Reader, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
output := kcmdutil.GetFlagString(c, "output")
shortOutput := output == "name"
if config.Dockerfile == "-" {
data, err := ioutil.ReadAll(in)
if err != nil {
return err
}
config.Dockerfile = string(data)
}
if err := setupAppConfig(f, out, c, args, config); err != nil {
return err
}
if err := setAppConfigLabels(c, config); err != nil {
return err
}
result, err := config.Run()
if err != nil {
return handleBuildError(c, err, fullName)
}
if len(config.Labels) == 0 && len(result.Name) > 0 {
config.Labels = map[string]string{"build": result.Name}
}
if err := setLabels(config.Labels, result); err != nil {
return err
}
if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {
return err
}
indent := " "
switch {
case shortOutput:
indent = ""
case len(output) != 0:
result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items)
if err != nil {
return err
}
return f.Factory.PrintObject(c, result.List, out)
default:
if len(config.Labels) > 0 {
fmt.Fprintf(out, "--> Creating resources with label %s ...\n", labels.SelectorFromSet(config.Labels).String())
} else {
fmt.Fprintf(out, "--> Creating resources ...\n")
}
}
if config.DryRun {
fmt.Fprintf(out, "--> Success (DRY RUN)\n")
return nil
}
mapper, _ := f.Object()
if err := createObjects(f, configcmd.NewPrintNameOrErrorAfterIndent(mapper, shortOutput, "created", out, c.Out(), indent), result); err != nil {
return err
}
if shortOutput {
return nil
}
fmt.Fprintf(out, "--> Success\n")
for _, item := range result.List.Items {
switch t := item.(type) {
case *buildapi.BuildConfig:
if len(t.Spec.Triggers) > 0 && t.Spec.Source.Binary == nil {
fmt.Fprintf(out, "%sBuild configuration %q created and build triggered.\n", indent, t.Name)
fmt.Fprintf(out, "%sRun '%s logs -f bc/%s' to stream the build progress.\n", indent, fullName, t.Name)
}
}
}
return nil
}
示例4: Run
// Run contains all the necessary functionality for the OpenShift cli new-build command
func (o *NewBuildOptions) Run() error {
config := o.Config
out := o.Out
output := o.Output
shortOutput := output == "name"
result, err := config.Run()
if err != nil {
return handleBuildError(err, o.CommandName, o.CommandPath)
}
if len(config.Labels) == 0 && len(result.Name) > 0 {
config.Labels = map[string]string{"build": result.Name}
}
if err := setLabels(config.Labels, result, false); err != nil {
return err
}
if err := setAnnotations(map[string]string{newcmd.GeneratedByNamespace: newcmd.GeneratedByNewBuild}, result); err != nil {
return err
}
indent := " "
switch {
case shortOutput:
indent = ""
case len(output) != 0:
return o.PrintObject(result.List)
default:
if len(config.Labels) > 0 {
fmt.Fprintf(out, "--> Creating resources with label %s ...\n", labels.SelectorFromSet(config.Labels).String())
} else {
fmt.Fprintf(out, "--> Creating resources ...\n")
}
}
if config.DryRun {
fmt.Fprintf(out, "--> Success (DRY RUN)\n")
return nil
}
afterFn := configcmd.NewPrintNameOrErrorAfterIndent(config.Mapper, shortOutput, "created", out, config.ErrOut, indent)
if err := createObjects(config, afterFn, result); err != nil {
return err
}
if shortOutput {
return nil
}
fmt.Fprintf(out, "--> Success\n")
for _, item := range result.List.Items {
switch t := item.(type) {
case *buildapi.BuildConfig:
if len(t.Spec.Triggers) > 0 && t.Spec.Source.Binary == nil {
fmt.Fprintf(out, "%sBuild configuration %q created and build triggered.\n", indent, t.Name)
fmt.Fprintf(out, "%sRun '%s logs -f bc/%s' to stream the build progress.\n", indent, o.CommandName, t.Name)
}
}
}
return nil
}