tadayosi commented on code in PR #3556:
URL: https://github.com/apache/camel-k/pull/3556#discussion_r950998567
##########
pkg/cmd/rebuild.go:
##########
@@ -27,25 +27,49 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
+ "github.com/apache/camel-k/pkg/util/kubernetes"
)
func newCmdRebuild(rootCmdOptions *RootCmdOptions) (*cobra.Command,
*rebuildCmdOptions) {
options := rebuildCmdOptions{
RootCmdOptions: rootCmdOptions,
}
cmd := cobra.Command{
- Use: "rebuild [integration]",
+ Use: "rebuild [integration1] [integration2] ...",
Short: "Clear the state of integrations to rebuild them",
Long: `Clear the state of one or more integrations causing a
rebuild.`,
PreRunE: decode(&options),
- RunE: options.rebuild,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.rebuild(cmd, args); err != nil {
+ fmt.Fprintln(cmd.ErrOrStderr(), err.Error())
+ }
+
+ return nil
+ },
}
+ cmd.Flags().Bool("all", false, "Rebuild all integrations")
+
return &cmd, &options
}
type rebuildCmdOptions struct {
*RootCmdOptions
+ RebuildAll bool `mapstructure:"all"`
+}
+
+func (o *rebuildCmdOptions) validate(args []string) error {
+ if o.RebuildAll && len(args) > 0 {
+ return errors.New("invalid combination: both all flag and named
integrations are set")
+ }
+ if !o.RebuildAll && len(args) == 0 {
+ return errors.New("invalid combination: neither all flag nor
named integrations are set")
Review Comment:
The error message is not intuitive a little bit, as the user would've just
run `kamel rebuild` without any combination of flags & args. You can just
suggest either specifying integration name(s) or --all flag.
##########
pkg/cmd/rebuild.go:
##########
@@ -27,25 +27,49 @@ import (
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
+ "github.com/apache/camel-k/pkg/util/kubernetes"
)
func newCmdRebuild(rootCmdOptions *RootCmdOptions) (*cobra.Command,
*rebuildCmdOptions) {
options := rebuildCmdOptions{
RootCmdOptions: rootCmdOptions,
}
cmd := cobra.Command{
- Use: "rebuild [integration]",
+ Use: "rebuild [integration1] [integration2] ...",
Short: "Clear the state of integrations to rebuild them",
Long: `Clear the state of one or more integrations causing a
rebuild.`,
PreRunE: decode(&options),
- RunE: options.rebuild,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if err := options.validate(args); err != nil {
+ return err
+ }
+ if err := options.rebuild(cmd, args); err != nil {
Review Comment:
You can just return the method result directly as there's no cleanup
afterwards. And no need for `return nil` at the bottom of the func.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]