github.com/kiegroup/kie-tools/packages/kn-plugin-workflow@v0.32.0/plugin/plugin.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one
     3   * or more contributor license agreements.  See the NOTICE file
     4   * distributed with this work for additional information
     5   * regarding copyright ownership.  The ASF licenses this file
     6   * to you under the Apache License, Version 2.0 (the
     7   * "License"); you may not use this file except in compliance
     8   * with the License.  You may obtain a copy of the License at
     9   *
    10   *  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19  
    20  package plugin
    21  
    22  import (
    23  	"os"
    24  	"runtime/debug"
    25  	"strings"
    26  
    27  	"github.com/kiegroup/kie-tools/packages/kn-plugin-workflow/pkg/root"
    28  	knplugin "knative.dev/client/pkg/kn/plugin"
    29  )
    30  
    31  type workflowPlugin struct{}
    32  
    33  var quarkusPlatformGroupId, quarkusVersion, pluginVersion string
    34  
    35  func init() {
    36  	knplugin.InternalPlugins = append(knplugin.InternalPlugins, &workflowPlugin{})
    37  }
    38  
    39  // Name is a plugin's name
    40  func (w *workflowPlugin) Name() string {
    41  	return "kn-workflow"
    42  }
    43  
    44  // Execute represents the plugin's entrypoint when called through kn
    45  func (w *workflowPlugin) Execute(args []string) error {
    46  	var version string
    47  	info, _ := debug.ReadBuildInfo()
    48  	for _, dep := range info.Deps {
    49  		if strings.Contains(dep.Path, "github.com/kiegroup/kie-tools/packages/kn-plugin-workflow") {
    50  			version = dep.Version
    51  		}
    52  	}
    53  
    54  	cmd := root.NewRootCommand(root.RootCmdConfig{Name: "kn\u00A0workflow", Version: version})
    55  	oldArgs := os.Args
    56  	defer (func() {
    57  		os.Args = oldArgs
    58  	})()
    59  	os.Args = append([]string{"kn-workflow"}, args...)
    60  	return cmd.Execute()
    61  }
    62  
    63  // Description is displayed in kn's plugin section
    64  func (w *workflowPlugin) Description() (string, error) {
    65  	return "Manage Workflow projects", nil
    66  }
    67  
    68  // CommandParts defines for plugin is executed from kn
    69  func (w *workflowPlugin) CommandParts() []string {
    70  	return []string{"workflow"}
    71  }
    72  
    73  // Path is empty because its an internal plugins
    74  func (w *workflowPlugin) Path() string {
    75  	return ""
    76  }