This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 3435eb15bb9e8c6fdba7bdc783fa3177dfd162eb
Author: Doru Bercea <[email protected]>
AuthorDate: Wed Oct 21 16:31:35 2020 -0400

    Add capability to process several additional dependencies flags.
---
 pkg/cmd/inspect.go | 87 ++++++++++++++++++++++++++++++------------------------
 pkg/cmd/root.go    |  1 -
 2 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/pkg/cmd/inspect.go b/pkg/cmd/inspect.go
index c3d9f723..fbf25c6 100644
--- a/pkg/cmd/inspect.go
+++ b/pkg/cmd/inspect.go
@@ -75,23 +75,23 @@ will be generated by calling Maven and then copied into the 
directory pointed to
        }
 
        cmd.Flags().Bool("all-dependencies", false, "Compute transitive 
dependencies and move them to directory pointed to by the 
--dependencies-directory flag.")
-       cmd.Flags().String("additional-dependencies", "", `Comma-separated list 
of additional top-level dependencies with the format:
+       cmd.Flags().StringArrayP("additional-dependencies", "d", nil, 
`Comma-separated lists of additional top-level dependencies with the format:
 <type>:<dependency-name>
 where <type> is one of {`+strings.Join(acceptedDependencyTypes, "|")+`}.`)
-       cmd.Flags().String("workspace", "", "Absolute path to workspace 
directory. Default: <kamel-invocation-directory>/workspace")
+       cmd.Flags().String("workspace", "", "Workspace directory. Default: 
<kamel-invocation-directory>/workspace")
+       cmd.Flags().String("dependencies-directory", "", "Directory that will 
contain all the computed dependencies. Default: 
<kamel-invocation-directory>/<kamel-workspace-directory>/dependencies")
        cmd.Flags().StringP("output", "o", "", "Output format. One of: 
json|yaml")
-       cmd.Flags().String("dependencies-directory", "", "Absolute path to 
directory containing all dependencies. Default: 
<kamel-invocation-directory>/workspace/dependencies")
 
        return &cmd, &options
 }
 
 type inspectCmdOptions struct {
        *RootCmdOptions
-       AllDependencies        bool   `mapstructure:"all-dependencies"`
-       OutputFormat           string `mapstructure:"output"`
-       AdditionalDependencies string `mapstructure:"additional-dependencies"`
-       Workspace              string `mapstructure:"workspace"`
-       DependenciesDirectory  string `mapstructure:"dependencies-directory"`
+       AllDependencies        bool     `mapstructure:"all-dependencies"`
+       OutputFormat           string   `mapstructure:"output"`
+       Workspace              string   `mapstructure:"workspace"`
+       DependenciesDirectory  string   `mapstructure:"dependencies-directory"`
+       AdditionalDependencies []string `mapstructure:"additional-dependencies"`
 }
 
 func (command *inspectCmdOptions) validate(args []string) error {
@@ -118,21 +118,23 @@ func (command *inspectCmdOptions) validate(args []string) 
error {
 
        // Validate list of additional dependencies i.e. make sure that each 
dependency has
        // a valid type.
-       if command.AdditionalDependencies != "" {
-               additionalDependencies := 
strings.Split(command.AdditionalDependencies, ",")
-
-               for _, dependency := range additionalDependencies {
-                       dependencyComponents := strings.Split(dependency, ":")
-
-                       TypeIsValid := false
-                       for _, dependencyType := range acceptedDependencyTypes {
-                               if dependencyType == dependencyComponents[0] {
-                                       TypeIsValid = true
+       if command.AdditionalDependencies != nil {
+               for _, additionalDependency := range 
command.AdditionalDependencies {
+                       additionalDependencies := 
strings.Split(additionalDependency, ",")
+
+                       for _, dependency := range additionalDependencies {
+                               dependencyComponents := 
strings.Split(dependency, ":")
+
+                               TypeIsValid := false
+                               for _, dependencyType := range 
acceptedDependencyTypes {
+                                       if dependencyType == 
dependencyComponents[0] {
+                                               TypeIsValid = true
+                                       }
                                }
-                       }
 
-                       if !TypeIsValid {
-                               return errors.New("Unexpected type for 
user-provided dependency: " + dependency + ", check command usage for valid 
format.")
+                               if !TypeIsValid {
+                                       return errors.New("Unexpected type for 
user-provided dependency: " + dependency + ", check command usage for valid 
format.")
+                               }
                        }
                }
        }
@@ -175,19 +177,8 @@ func (command *inspectCmdOptions) initialize(args 
[]string) error {
 }
 
 func (command *inspectCmdOptions) run(args []string) error {
-       // Attempt to reuse existing Camel catalog if one is present.
-       catalog, err := camel.MainCatalog()
-       if err != nil {
-               return err
-       }
-
-       // Generate catalog if one was not found.
-       if catalog == nil {
-               catalog, err = generateCatalog()
-               if err != nil {
-                       return err
-               }
-       }
+       // Fetch existing catalog or create new one if one does not already 
exist.
+       catalog, err := createCamelCatalog()
 
        // Get top-level dependencies, this is the default behavior when no 
other options are provided.
        dependencies, err := getTopLevelDependencies(catalog, 
command.OutputFormat, args)
@@ -196,10 +187,12 @@ func (command *inspectCmdOptions) run(args []string) 
error {
        }
 
        // Add additional user-provided dependencies.
-       if command.AdditionalDependencies != "" {
-               additionalDependencies := 
strings.Split(command.AdditionalDependencies, ",")
-               for _, dependency := range additionalDependencies {
-                       dependencies = append(dependencies, dependency)
+       if command.AdditionalDependencies != nil {
+               for _, additionalDependency := range 
command.AdditionalDependencies {
+                       additionalDependencies := 
strings.Split(additionalDependency, ",")
+                       for _, dependency := range additionalDependencies {
+                               dependencies = append(dependencies, dependency)
+                       }
                }
        }
 
@@ -376,3 +369,21 @@ func createAndSetDependenciesDirectory(command 
*inspectCmdOptions) error {
 
        return nil
 }
+
+func createCamelCatalog() (*camel.RuntimeCatalog, error) {
+       // Attempt to reuse existing Camel catalog if one is present.
+       catalog, err := camel.MainCatalog()
+       if err != nil {
+               return nil, err
+       }
+
+       // Generate catalog if one was not found.
+       if catalog == nil {
+               catalog, err = generateCatalog()
+               if err != nil {
+                       return nil, err
+               }
+       }
+
+       return catalog, nil
+}
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index 2eab1ef..6be4a68 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -137,7 +137,6 @@ func addKamelSubcommands(cmd *cobra.Command, options 
*RootCmdOptions) {
        cmd.AddCommand(cmdOnly(newCmdBuilder(options)))
        cmd.AddCommand(cmdOnly(newCmdInit(options)))
        cmd.AddCommand(cmdOnly(newCmdDebug(options)))
-       cmd.AddCommand(cmdOnly(newCmdInspect(options)))
 }
 
 func addHelpSubCommands(cmd *cobra.Command, options *RootCmdOptions) error {

Reply via email to