Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): more user-friendly error messages for kamel local subcommands #3499

Merged
merged 9 commits into from
Aug 7, 2022
2 changes: 2 additions & 0 deletions e2e/local/local_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestLocalBuild(t *testing.T) {

kamelBuild := KamelWithContext(ctx, "local", "build", file, "--image", image)
kamelBuild.SetOut(pipew)
kamelBuild.SetErr(pipew)

msgTagged := "Successfully tagged"
logScanner := testutil.NewLogScanner(ctx, piper, msgTagged, image)
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestLocalBuildWithTrait(t *testing.T) {

kamelBuild := KamelWithContext(ctx, "local", "build", file, "--image", image)
kamelBuild.SetOut(pipew)
kamelBuild.SetErr(pipew)

msgWarning := "Warning: traits are specified but don't take effect for local run: [jolokia.enabled=true]"
msgTagged := "Successfully tagged"
Expand Down
9 changes: 4 additions & 5 deletions e2e/local/local_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package local
import (
"context"
"io"
"os"
"strings"
"testing"

Expand All @@ -48,6 +47,7 @@ func TestLocalRun(t *testing.T) {

kamelRun := KamelWithContext(ctx, "local", "run", file)
kamelRun.SetOut(pipew)
kamelRun.SetErr(pipew)

logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")

Expand All @@ -73,6 +73,7 @@ func TestLocalRunWithDependencies(t *testing.T) {

kamelRun := KamelWithContext(ctx, "local", "run", file, "-d", "camel-amqp")
kamelRun.SetOut(pipew)
kamelRun.SetErr(pipew)

logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")

Expand All @@ -99,6 +100,7 @@ func TestLocalRunContainerize(t *testing.T) {

kamelRun := KamelWithContext(ctx, "local", "run", file, "--image", image, "--containerize")
kamelRun.SetOut(pipew)
kamelRun.SetErr(pipew)

logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")

Expand All @@ -116,10 +118,6 @@ func TestLocalRunContainerize(t *testing.T) {
func TestLocalRunIntegrationDirectory(t *testing.T) {
RegisterTestingT(t)

if os.Getenv("CI") == "true" {
t.Skip("TODO: Temporarily disabled as this test is flaky and hangs the test process")
}

ctx1, cancel1 := context.WithCancel(TestContext)
defer cancel1()

Expand All @@ -146,6 +144,7 @@ func TestLocalRunIntegrationDirectory(t *testing.T) {

kamelRun := KamelWithContext(ctx2, "local", "run", "--integration-directory", dir)
kamelRun.SetOut(pipew)
kamelRun.SetErr(pipew)

logScanner := testutil.NewLogScanner(ctx2, piper, "Magicstring!")

Expand Down
2 changes: 1 addition & 1 deletion e2e/namespace/install/cli/dev_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"path/filepath"

. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
Expand Down
18 changes: 15 additions & 3 deletions pkg/cmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ import (
"github.com/spf13/cobra"
)

// Usage descritions of common flags that are shared across some of the subcommands.
const (
usageImage = `Full path to integration image including registry, e.g. "docker.io/user/app"`
usageIntegrationDirectory = "Directory to hold local integration files"
usagePropertyFile = "Add a property file to the integration"
usageProperty = "Add a Camel property to the integration"
)

// newCmdLocal -- Add local kamel subcommand with several other subcommands of its own.
func newCmdLocal(rootCmdOptions *RootCmdOptions) (*cobra.Command, *LocalCmdOptions) {
options := LocalCmdOptions{
Expand All @@ -41,6 +49,8 @@ func newCmdLocal(rootCmdOptions *RootCmdOptions) (*cobra.Command, *LocalCmdOptio
}

cmd.PersistentFlags().StringArrayVarP(&options.Dependencies, "dependency", "d", nil, usageDependency)
cmd.PersistentFlags().StringArrayVar(&options.MavenRepositories, "maven-repository", nil,
"Use a maven repository")

// hidden flags for compatibility with kamel run
cmd.PersistentFlags().StringArrayVarP(&options.Traits, "trait", "t", nil, "")
Expand All @@ -57,8 +67,9 @@ func newCmdLocal(rootCmdOptions *RootCmdOptions) (*cobra.Command, *LocalCmdOptio

type LocalCmdOptions struct {
*RootCmdOptions
Dependencies []string `mapstructure:"dependencies"`
Traits []string `mapstructure:"traits"`
Dependencies []string `mapstructure:"dependencies"`
MavenRepositories []string `mapstructure:"maven-repositories"`
Traits []string `mapstructure:"traits"`
}

func (o *LocalCmdOptions) persistentPreRun(cmd *cobra.Command, args []string) error {
Expand All @@ -75,6 +86,7 @@ func (o *LocalCmdOptions) persistentPreRun(cmd *cobra.Command, args []string) er

func warnTraitUsages(cmd *cobra.Command, traits []string) {
if len(traits) > 0 {
fmt.Fprintf(cmd.OutOrStdout(), "Warning: traits are specified but don't take effect for local run: %v\n", traits)
fmt.Fprintf(cmd.OutOrStdout(),
"Warning: traits are specified but don't take effect for local run: %v\n", traits)
}
}
Loading