Skip to content

Commit 30a0b59

Browse files
Merge pull request #19355 from nak3/warn-binarybuild-loglevel
Distinguish warning message between --build-loglevel and --env with binary builds
2 parents 835a0ae + 9a2edf2 commit 30a0b59

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

pkg/oc/cli/cmd/startbuild.go

+38-19
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ var (
8888

8989
// NewCmdStartBuild implements the OpenShift cli start-build command
9090
func NewCmdStartBuild(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
91-
o := &StartBuildOptions{}
91+
o := &StartBuildOptions{
92+
In: in,
93+
Out: out,
94+
ErrOut: errout,
95+
}
9296

9397
cmd := &cobra.Command{
9498
Use: "start-build (BUILDCONFIG | --from-build=BUILD)",
@@ -97,7 +101,8 @@ func NewCmdStartBuild(fullName string, f *clientcmd.Factory, in io.Reader, out,
97101
Example: fmt.Sprintf(startBuildExample, fullName),
98102
SuggestFor: []string{"build", "builds"},
99103
Run: func(cmd *cobra.Command, args []string) {
100-
kcmdutil.CheckErr(o.Complete(f, in, out, errout, cmd, fullName, args))
104+
kcmdutil.CheckErr(o.Complete(f, cmd, fullName, args))
105+
kcmdutil.CheckErr(o.Validate())
101106
kcmdutil.CheckErr(o.Run())
102107
},
103108
}
@@ -168,11 +173,8 @@ type StartBuildOptions struct {
168173
Namespace string
169174
}
170175

171-
func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *cobra.Command, cmdFullName string, args []string) error {
176+
func (o *StartBuildOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, cmdFullName string, args []string) error {
172177
var err error
173-
o.In = in
174-
o.Out = out
175-
o.ErrOut = errout
176178
o.Git = git.NewRepository()
177179
o.ClientConfig, err = f.ClientConfig()
178180
if err != nil {
@@ -220,20 +222,14 @@ func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, er
220222
return kcmdutil.UsageErrorf(cmd, "The '--from-webhook' flag is incompatible with arguments and all '--from-*' flags")
221223
}
222224
if !strings.HasSuffix(webhook, "/generic") {
223-
fmt.Fprintf(errout, "warning: the '--from-webhook' flag should be called with a generic webhook URL.\n")
225+
fmt.Fprintf(o.ErrOut, "warning: the '--from-webhook' flag should be called with a generic webhook URL.\n")
224226
}
225227
return nil
226228

227229
case len(args) != 1 && len(buildName) == 0:
228230
return kcmdutil.UsageErrorf(cmd, "Must pass a name of a build config or specify build name with '--from-build' flag.\nUse \"%s get bc\" to list all available build configs.", cmdFullName)
229231
}
230232

231-
if len(buildName) != 0 && o.AsBinary {
232-
// TODO: we should support this, it should be possible to clone a build to run again with new uploaded artifacts.
233-
// Doing so requires introducing a new clonebinary endpoint.
234-
return kcmdutil.UsageErrorf(cmd, "Cannot use '--from-build' flag with binary builds")
235-
}
236-
237233
namespace, _, err := f.DefaultNamespace()
238234
if err != nil {
239235
return err
@@ -288,16 +284,12 @@ func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, er
288284
name = ref.Name
289285
}
290286

291-
if len(name) == 0 {
292-
return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
293-
}
294-
295287
o.Namespace = namespace
296288
o.Name = name
297289

298290
// Handle environment variables
299291
cmdutil.WarnAboutCommaSeparation(o.ErrOut, o.Env, "--env")
300-
env, _, err := utilenv.ParseEnv(o.Env, in)
292+
env, _, err := utilenv.ParseEnv(o.Env, o.In)
301293
if err != nil {
302294
return err
303295
}
@@ -308,7 +300,7 @@ func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, er
308300

309301
// Handle Docker build arguments. In order to leverage existing logic, we
310302
// first create an EnvVar array, then convert it to []docker.BuildArg
311-
buildArgs, err := utilenv.ParseBuildArg(o.Args, in)
303+
buildArgs, err := utilenv.ParseBuildArg(o.Args, o.In)
312304
if err != nil {
313305
return err
314306
}
@@ -317,6 +309,33 @@ func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, er
317309
return nil
318310
}
319311

312+
// Validate returns validation errors regarding start-build
313+
func (o *StartBuildOptions) Validate() error {
314+
if o.AsBinary {
315+
if len(o.LogLevel) > 0 {
316+
fmt.Fprintf(o.ErrOut, "WARNING: Specifying --build-loglevel with binary builds is not supported.\n")
317+
}
318+
if len(o.EnvVar) > 1 || (len(o.LogLevel) == 0 && len(o.EnvVar) > 0) {
319+
fmt.Fprintf(o.ErrOut, "WARNING: Specifying environment variables with binary builds is not supported.\n")
320+
}
321+
if len(o.BuildArgs) > 0 {
322+
fmt.Fprintf(o.ErrOut, "WARNING: Specifying build arguments with binary builds is not supported.\n")
323+
}
324+
}
325+
326+
if len(o.FromBuild) != 0 && o.AsBinary {
327+
// TODO: we should support this, it should be possible to clone a build to run again with new uploaded artifacts.
328+
// Doing so requires introducing a new clonebinary endpoint.
329+
return fmt.Errorf("Cannot use '--from-build' flag with binary builds")
330+
}
331+
332+
if len(o.Name) == 0 && len(o.FromWebhook) == 0 && len(o.FromBuild) == 0 {
333+
return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
334+
}
335+
336+
return nil
337+
}
338+
320339
// Run contains all the necessary functionality for the OpenShift cli start-build command
321340
func (o *StartBuildOptions) Run() error {
322341
if len(o.FromWebhook) > 0 {

0 commit comments

Comments
 (0)