Add local run command. Resolve all modeline options.
diff --git a/pkg/cmd/local.go b/pkg/cmd/local.go
new file mode 100644
index 0000000..89b7740
--- /dev/null
+++ b/pkg/cmd/local.go
@@ -0,0 +1,55 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+// NewCmdLocal -- Add local kamel subcommand with several other subcommands of its own.
+func newCmdLocal(rootCmdOptions *RootCmdOptions) *cobra.Command {
+ cmd := cobra.Command{
+ Use: "local [sub-command]",
+ Short: "Perform integration actions locally.",
+ Long: `Perform integration actions locally given a set of input integration files.`,
+ Annotations: map[string]string{
+ offlineCommandLabel: "true",
+ },
+ }
+
+ return &cmd
+}
+
+func addLocalSubCommands(cmd *cobra.Command, options *RootCmdOptions) error {
+ var localCmd *cobra.Command
+ for _, c := range cmd.Commands() {
+ if c.Name() == "local" {
+ localCmd = c
+ break
+ }
+ }
+
+ if localCmd == nil {
+ return errors.New("could not find any configured local command")
+ }
+
+ localCmd.AddCommand(cmdOnly(newCmdLocalRun(options)))
+
+ return nil
+}
diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index 4a68877..f2b86f4 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -30,7 +30,7 @@
}
cmd := cobra.Command{
- Use: "local-run [integration files]",
+ Use: "run [integration files]",
Short: "Run integration locally.",
Long: `Run integration locally using the input integration files.`,
PreRunE: decode(&options),
diff --git a/pkg/cmd/local_run_test.go b/pkg/cmd/local_run_test.go
index 2858021..72f84f2 100644
--- a/pkg/cmd/local_run_test.go
+++ b/pkg/cmd/local_run_test.go
@@ -24,14 +24,16 @@
"github.com/spf13/cobra"
)
-func addTestLocalRunCmd(options *RootCmdOptions, rootCmd *cobra.Command) *localRunCmdOptions {
+func addTestLocalRunCmd(rootCmdOptions *RootCmdOptions, rootCmd *cobra.Command) *localRunCmdOptions {
//add a testing version of run Command
- localRunCmd, localRunCmdOptions := newCmdLocalRun(options)
+ localCmd := newCmdLocal(rootCmdOptions)
+ localRunCmd, localRunCmdOptions := newCmdLocalRun(rootCmdOptions)
localRunCmd.RunE = func(c *cobra.Command, args []string) error {
return nil
}
localRunCmd.Args = test.ArbitraryArgs
- rootCmd.AddCommand(localRunCmd)
+ localCmd.AddCommand(localRunCmd)
+ rootCmd.AddCommand(localCmd)
return localRunCmdOptions
}
@@ -42,7 +44,7 @@
kamelTestPostAddCommandInit(t, rootCmd)
- _, err := test.ExecuteCommand(rootCmd, "local-run", "route.java", "--property-file", "file1.properties", "--property-file", "file2.properties")
+ _, err := test.ExecuteCommand(rootCmd, "local", "run", "route.java", "--property-file", "file1.properties", "--property-file", "file2.properties")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@@ -62,7 +64,7 @@
kamelTestPostAddCommandInit(t, rootCmd)
- _, err := test.ExecuteCommand(rootCmd, "local-run", "route.java", "-d", "mvn:camel-component-1", "-d", "mvn:camel-component-2")
+ _, err := test.ExecuteCommand(rootCmd, "local", "run", "route.java", "-d", "mvn:camel-component-1", "-d", "mvn:camel-component-2")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go
index b232110..9e3331f 100644
--- a/pkg/cmd/modeline.go
+++ b/pkg/cmd/modeline.go
@@ -31,6 +31,7 @@
const (
runCmdName = "run"
+ localCmdName = "local"
runCmdSourcesArgs = "source"
)
@@ -98,9 +99,14 @@
fg := target.Flags()
- additionalSources, err := fg.GetStringArray(runCmdSourcesArgs)
- if err != nil {
- return nil, nil, err
+ // Only the run command has source flag (for now). Remove condition when
+ // local run also supports source.
+ additionalSources := make([]string, 0)
+ if target.Name() == runCmdName && target.Parent().Name() != localCmdName {
+ additionalSources, err = fg.GetStringArray(runCmdSourcesArgs)
+ if err != nil {
+ return nil, nil, err
+ }
}
files := make([]string, 0, len(fg.Args())+len(additionalSources))
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index eba43c2..c56d369 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -61,6 +61,10 @@
return cmd, err
}
+ if err := addLocalSubCommands(cmd, &options); err != nil {
+ return cmd, err
+ }
+
err = kamelPostAddCommandInit(cmd)
return cmd, err
@@ -139,7 +143,7 @@
cmd.AddCommand(cmdOnly(newCmdInit(options)))
cmd.AddCommand(cmdOnly(newCmdDebug(options)))
cmd.AddCommand(cmdOnly(newCmdInspect(options)))
- cmd.AddCommand(cmdOnly(newCmdLocalRun(options)))
+ cmd.AddCommand(newCmdLocal(options))
}
func addHelpSubCommands(cmd *cobra.Command, options *RootCmdOptions) error {
diff --git a/pkg/cmd/util.go b/pkg/cmd/util.go
index 8d5ac14..3e364a6 100644
--- a/pkg/cmd/util.go
+++ b/pkg/cmd/util.go
@@ -24,11 +24,12 @@
"encoding/csv"
"encoding/json"
"fmt"
- "github.com/apache/camel-k/pkg/util/gzip"
"log"
"reflect"
"strings"
+ "github.com/apache/camel-k/pkg/util/gzip"
+
"github.com/mitchellh/mapstructure"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"