Commit 85a5f47 1 parent 2c7c18d commit 85a5f47 Copy full SHA for 85a5f47
File tree 2 files changed +48
-1
lines changed
2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,15 @@ var root = &cobra.Command{
26
26
Create and run Functions as a Service.` ,
27
27
}
28
28
29
+ // NewRootCmd is used to initialize faas as kn plugin
30
+ func NewRootCmd () * cobra.Command {
31
+ return root
32
+ }
33
+
29
34
// When the code is loaded into memory upon invocation, the cobra/viper packages
30
35
// are invoked to gather system context. This includes reading the configuration
31
36
// file, environment variables, and parsing the command flags.
32
- func init () {
37
+ func Init () {
33
38
// read in environment variables that match
34
39
viper .AutomaticEnv ()
35
40
Original file line number Diff line number Diff line change
1
+ package plugin
2
+
3
+ import (
4
+ "github.com/boson-project/faas/cmd"
5
+ "knative.dev/client/pkg/kn/plugin"
6
+ "os"
7
+ )
8
+
9
+ func init () {
10
+ plugin .InternalPlugins = append (plugin .InternalPlugins , & faasPlugin {})
11
+ }
12
+
13
+ type faasPlugin struct {}
14
+
15
+ func (f * faasPlugin ) Name () string {
16
+ return "kn-faas"
17
+ }
18
+
19
+ func (f * faasPlugin ) Execute (args []string ) error {
20
+ rootCmd := cmd .NewRootCmd ()
21
+ cmd .Init ()
22
+ oldArgs := os .Args
23
+ defer (func () {
24
+ os .Args = oldArgs
25
+ })()
26
+ os .Args = append ([]string { "kn-faas" }, args ... )
27
+ return rootCmd .Execute ()
28
+ }
29
+
30
+ // Description for faas subcommand visible in 'kn --help'
31
+ func (f * faasPlugin ) Description () (string , error ) {
32
+ return "Function as a Service plugin" , nil
33
+ }
34
+
35
+ func (f * faasPlugin ) CommandParts () []string {
36
+ return []string { "faas" }
37
+ }
38
+
39
+ // Path is empty because its an internal plugins
40
+ func (f * faasPlugin ) Path () string {
41
+ return ""
42
+ }
You can’t perform that action at this time.
0 commit comments