Browse code

Use cmdutil.PrintSuccess to print objects

Fabiano Franz authored on 2015/10/28 04:52:18
Showing 10 changed files
... ...
@@ -47,6 +47,7 @@ func NewCmdCancelBuild(fullName string, f *clientcmd.Factory, out io.Writer) *co
47 47
 
48 48
 	cmd.Flags().Bool("dump-logs", false, "Specify if the build logs for the cancelled build should be shown.")
49 49
 	cmd.Flags().Bool("restart", false, "Specify if a new build should be created after the current build is cancelled.")
50
+	//cmdutil.AddOutputFlagsForMutation(cmd)
50 51
 	return cmd
51 52
 }
52 53
 
... ...
@@ -107,6 +108,10 @@ func RunCancelBuild(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, arg
107 107
 	}
108 108
 	glog.V(2).Infof("Build %s was cancelled.", buildName)
109 109
 
110
+	// mapper, typer := f.Object()
111
+	// resourceMapper := &resource.Mapper{ObjectTyper: typer, RESTMapper: mapper, ClientMapper: f.ClientMapperForCommand()}
112
+	// shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
113
+
110 114
 	// Create a new build with the same configuration.
111 115
 	if cmdutil.GetFlagBool(cmd, "restart") {
112 116
 		request := &buildapi.BuildRequest{
... ...
@@ -118,8 +123,19 @@ func RunCancelBuild(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, arg
118 118
 		}
119 119
 		glog.V(2).Infof("Restarted build %s.", buildName)
120 120
 		fmt.Fprintf(out, "%s\n", newBuild.Name)
121
+		// fmt.Fprintf(out, "%s\n", newBuild.Name)
122
+		// info, err := resourceMapper.InfoForObject(newBuild)
123
+		// if err != nil {
124
+		// 	return err
125
+		// }
126
+		//cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "restarted")
121 127
 	} else {
122 128
 		fmt.Fprintf(out, "%s\n", build.Name)
129
+		// info, err := resourceMapper.InfoForObject(build)
130
+		// if err != nil {
131
+		// 	return err
132
+		// }
133
+		// cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "cancelled")
123 134
 	}
124 135
 	return nil
125 136
 }
... ...
@@ -303,7 +303,9 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
303 303
 			continue
304 304
 		}
305 305
 		info.Refresh(obj, true)
306
-		fmt.Fprintf(out, "%s/%s\n", info.Mapping.Resource, info.Name)
306
+
307
+		shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
308
+		cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "updated")
307 309
 	}
308 310
 	if failed {
309 311
 		return errExit
... ...
@@ -67,7 +67,7 @@ func NewCmdProcess(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.
67 67
 	cmd.Flags().BoolP("parameters", "", false, "Do not process but only print available parameters")
68 68
 	cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this template")
69 69
 
70
-	cmd.Flags().StringP("output", "o", "json", "Output format. One of: describe|json|yaml|template|templatefile.")
70
+	cmd.Flags().StringP("output", "o", "json", "Output format. One of: describe|json|yaml|name|template|templatefile.")
71 71
 	cmd.Flags().Bool("raw", false, "If true output the processed template instead of the template's objects. Implied by -o describe")
72 72
 	cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).")
73 73
 	cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile.  The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]")
... ...
@@ -85,7 +85,7 @@ func NewCmdRollback(fullName string, f *clientcmd.Factory, out io.Writer) *cobra
85 85
 	cmd.Flags().BoolVar(&opts.IncludeStrategy, "change-strategy", false, "Include the previous deployment's strategy in the rollback")
86 86
 	cmd.Flags().BoolVar(&opts.IncludeScalingSettings, "change-scaling-settings", false, "Include the previous deployment's replicationController replica count and selector in the rollback")
87 87
 	cmd.Flags().BoolVarP(&opts.DryRun, "dry-run", "d", false, "Instead of performing the rollback, describe what the rollback will look like in human-readable form")
88
-	cmd.Flags().StringVarP(&opts.Format, "output", "o", "", "Instead of performing the rollback, print the updated deployment configuration in the specified format (json|yaml|template|templatefile)")
88
+	cmd.Flags().StringVarP(&opts.Format, "output", "o", "", "Instead of performing the rollback, print the updated deployment configuration in the specified format (json|yaml|name|template|templatefile)")
89 89
 	cmd.Flags().StringVarP(&opts.Template, "template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile.")
90 90
 	cmd.Flags().IntVar(&opts.DesiredVersion, "to-version", 0, "A config version to rollback to. Specifying version 0 is the same as omitting a version (the version will be auto-detected). This option is ignored when specifying a deployment.")
91 91
 
... ...
@@ -100,6 +100,8 @@ func NewCmdStartBuild(fullName string, f *clientcmd.Factory, in io.Reader, out i
100 100
 
101 101
 	cmd.Flags().String("git-post-receive", "", "The contents of the post-receive hook to trigger a build")
102 102
 	cmd.Flags().String("git-repository", "", "The path to the git repository for post-receive; defaults to the current directory")
103
+
104
+	// cmdutil.AddOutputFlagsForMutation(cmd)
103 105
 	return cmd
104 106
 }
105 107
 
... ...
@@ -113,9 +115,6 @@ func RunStartBuild(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra
113 113
 	fromFile := cmdutil.GetFlagString(cmd, "from-file")
114 114
 	fromDir := cmdutil.GetFlagString(cmd, "from-dir")
115 115
 	fromRepo := cmdutil.GetFlagString(cmd, "from-repo")
116
-	//shortOutput := false
117
-
118
-	//mapper, _ := f.Object()
119 116
 
120 117
 	switch {
121 118
 	case len(webhook) > 0:
... ...
@@ -190,8 +189,15 @@ func RunStartBuild(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra
190 190
 		}
191 191
 	}
192 192
 
193
-	//cmdutil.PrintSuccess(mapper, shortOutput, out, "Build", newBuild.Name, "started")
194 193
 	fmt.Fprintln(out, newBuild.Name)
194
+	// mapper, typer := f.Object()
195
+	// resourceMapper := &resource.Mapper{ObjectTyper: typer, RESTMapper: mapper, ClientMapper: f.ClientMapperForCommand()}
196
+	// info, err := resourceMapper.InfoForObject(newBuild)
197
+	// if err != nil {
198
+	// 	return err
199
+	// }
200
+	// shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
201
+	// cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "started")
195 202
 
196 203
 	var (
197 204
 		wg      sync.WaitGroup
... ...
@@ -23,7 +23,8 @@ type Bulk struct {
23 23
 func NewPrintNameOrErrorAfter(mapper meta.RESTMapper, short bool, operation string, out, errs io.Writer) func(*resource.Info, error) {
24 24
 	return func(info *resource.Info, err error) {
25 25
 		if err == nil {
26
-			cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Kind, info.Name, operation)
26
+			//cmdutil.PrintSuccess(mapper, short, out, info.Mapping.Resource, info.Name, operation)
27
+			cmdutil.PrintSuccess(mapper, short, out, info.Mapping.Kind, info.Name, operation)
27 28
 		} else {
28 29
 			fmt.Fprintf(errs, "error: %v\n", err)
29 30
 		}
... ...
@@ -24,12 +24,12 @@ oc get secret json-with-extension yml-with-extension
24 24
 echo "resource-builder: ok"
25 25
 
26 26
 oc get pods --match-server-version
27
-oc create -f examples/hello-openshift/hello-pod.json
27
+[ "$(oc create -f examples/hello-openshift/hello-pod.json 2>&1 | grep 'pod "hello-openshift" created')" ]
28 28
 oc describe pod hello-openshift
29 29
 oc delete pods hello-openshift
30 30
 echo "pods: ok"
31 31
 
32
-oc create -f examples/hello-openshift/hello-pod.json
32
+[ "$(oc create -f examples/hello-openshift/hello-pod.json -o name 2>&1 | grep 'pod/hello-openshift')" ]
33 33
 tryuntil oc label pod/hello-openshift acustom=label # can race against scheduling and status updates
34 34
 [ "$(oc describe pod/hello-openshift | grep 'acustom=label')" ]
35 35
 tryuntil oc annotate pod/hello-openshift foo=bar # can race against scheduling and status updates
... ...
@@ -55,6 +55,6 @@ echo "start-build: ok"
55 55
 oc cancel-build "${started}" --dump-logs --restart
56 56
 echo "cancel-build: ok"
57 57
 
58
-oc delete is/ruby-20-centos7-buildcli
59
-oc delete bc/ruby-sample-build-validtag
60
-oc delete bc/ruby-sample-build-invalidtag
58
+[ "$(oc delete is/ruby-20-centos7-buildcli | grep 'imagestream "ruby-20-centos7-buildcli" deleted')" ]
59
+[ "$(oc delete bc/ruby-sample-build-validtag -o name | grep 'buildconfig/ruby-sample-build-validtag')" ]
60
+[ "$(oc delete bc/ruby-sample-build-invalidtag | grep 'buildconfig "ruby-sample-build-invalidtag" deleted')" ]
... ...
@@ -14,6 +14,7 @@ oc get deploymentConfigs
14 14
 oc get dc
15 15
 oc create -f test/integration/fixtures/test-deployment-config.json
16 16
 oc describe deploymentConfigs test-deployment-config
17
+[ "$(oc get dc -o name | grep 'deploymentconfig/test-deployment-config')" ]
17 18
 [ "$(oc describe dc test-deployment-config | grep 'deploymentconfig=test-deployment-config')" ]
18 19
 [ "$(oc env dc/test-deployment-config --list | grep TEST=value)" ]
19 20
 [ ! "$(oc env dc/test-deployment-config TEST- --list | grep TEST=value)" ]
... ...
@@ -72,7 +72,9 @@ oc get template ruby-helloworld-sample
72 72
 [ "$(oc new-app --search mysql --param=FOO=BAR 2>&1 | grep "can't be used")" ]
73 73
 oc delete imageStreams --all
74 74
 # check that we can create from the template without errors
75
-oc new-app ruby-helloworld-sample -l app=helloworld
75
+[ "$(oc new-app ruby-helloworld-sample -l app=helloworld 2>&1 | grep 'Service "frontend" created')" ]
76
+oc delete all -l app=helloworld
77
+[ "$(oc new-app ruby-helloworld-sample -l app=helloworld -o name 2>&1 | grep 'Service/frontend')" ]
76 78
 oc delete all -l app=helloworld
77 79
 # create from template with code explicitly set is not supported
78 80
 [ ! "$(oc new-app ruby-helloworld-sample~git@github.com/mfojtik/sinatra-app-example)" ]