mirror of https://github.com/knative/func.git
feat(kn): Enable faas to be integrated as plugin to kn (#155)
Provides capabilities for the faas CLI to exist as a plugin in the upstream kn CLI. Tested with kn 0.17
This commit is contained in:
parent
2c7c18dd9b
commit
85a5f475eb
|
@ -26,10 +26,15 @@ var root = &cobra.Command{
|
|||
Create and run Functions as a Service.`,
|
||||
}
|
||||
|
||||
// NewRootCmd is used to initialize faas as kn plugin
|
||||
func NewRootCmd() *cobra.Command {
|
||||
return root
|
||||
}
|
||||
|
||||
// When the code is loaded into memory upon invocation, the cobra/viper packages
|
||||
// are invoked to gather system context. This includes reading the configuration
|
||||
// file, environment variables, and parsing the command flags.
|
||||
func init() {
|
||||
func Init() {
|
||||
// read in environment variables that match
|
||||
viper.AutomaticEnv()
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/boson-project/faas/cmd"
|
||||
"knative.dev/client/pkg/kn/plugin"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.InternalPlugins = append(plugin.InternalPlugins, &faasPlugin{})
|
||||
}
|
||||
|
||||
type faasPlugin struct {}
|
||||
|
||||
func (f *faasPlugin) Name() string {
|
||||
return "kn-faas"
|
||||
}
|
||||
|
||||
func (f *faasPlugin) Execute(args []string) error {
|
||||
rootCmd := cmd.NewRootCmd()
|
||||
cmd.Init()
|
||||
oldArgs := os.Args
|
||||
defer (func() {
|
||||
os.Args = oldArgs
|
||||
})()
|
||||
os.Args = append([]string { "kn-faas" }, args...)
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
// Description for faas subcommand visible in 'kn --help'
|
||||
func (f *faasPlugin) Description() (string, error) {
|
||||
return "Function as a Service plugin", nil
|
||||
}
|
||||
|
||||
func (f *faasPlugin) CommandParts() []string {
|
||||
return []string{ "faas"}
|
||||
}
|
||||
|
||||
// Path is empty because its an internal plugins
|
||||
func (f *faasPlugin) Path() string {
|
||||
return ""
|
||||
}
|
Loading…
Reference in New Issue