File tree 4 files changed +36
-4
lines changed
docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1
4 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ limitations under the License.
16
16
package cmd
17
17
18
18
import (
19
+ "fmt"
20
+
19
21
"v1/scaffolds"
20
22
21
23
"github.com/spf13/pflag"
@@ -43,7 +45,13 @@ func flagsCmd(pr *external.PluginRequest) external.PluginResponse {
43
45
flagsToParse .Bool ("api" , false , "sets the api flag to true" )
44
46
flagsToParse .Bool ("webhook" , false , "sets the webhook flag to true" )
45
47
46
- flagsToParse .Parse (pr .Args )
48
+ if err := flagsToParse .Parse (pr .Args ); err != nil {
49
+ pluginResponse .Error = true
50
+ pluginResponse .ErrorMsgs = []string {
51
+ fmt .Sprintf ("failed to parse flags: %s" , err .Error ()),
52
+ }
53
+ return pluginResponse
54
+ }
47
55
48
56
initFlag , _ := flagsToParse .GetBool ("init" )
49
57
apiFlag , _ := flagsToParse .GetBool ("api" )
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ limitations under the License.
16
16
package cmd
17
17
18
18
import (
19
+ "fmt"
20
+
19
21
"v1/scaffolds"
20
22
21
23
"github.com/spf13/pflag"
@@ -41,7 +43,13 @@ func metadataCmd(pr *external.PluginRequest) external.PluginResponse {
41
43
flagsToParse .Bool ("api" , false , "sets the api flag to true" )
42
44
flagsToParse .Bool ("webhook" , false , "sets the webhook flag to true" )
43
45
44
- flagsToParse .Parse (pr .Args )
46
+ if err := flagsToParse .Parse (pr .Args ); err != nil {
47
+ pluginResponse .Error = true
48
+ pluginResponse .ErrorMsgs = []string {
49
+ fmt .Sprintf ("failed to parse flags: %s" , err .Error ()),
50
+ }
51
+ return pluginResponse
52
+ }
45
53
46
54
initFlag , _ := flagsToParse .GetBool ("init" )
47
55
apiFlag , _ := flagsToParse .GetBool ("api" )
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ limitations under the License.
16
16
package scaffolds
17
17
18
18
import (
19
+ "fmt"
20
+
19
21
"v1/scaffolds/internal/templates"
20
22
21
23
"github.com/spf13/pflag"
@@ -55,7 +57,13 @@ func InitCmd(pr *external.PluginRequest) external.PluginResponse {
55
57
// Here is an example of parsing a flag from a Kubebuilder external plugin request
56
58
flags := pflag .NewFlagSet ("initFlags" , pflag .ContinueOnError )
57
59
flags .String ("domain" , "example.domain.com" , "sets the domain added in the scaffolded initFile.txt" )
58
- flags .Parse (pr .Args )
60
+ if err := flags .Parse (pr .Args ); err != nil {
61
+ pluginResponse .Error = true
62
+ pluginResponse .ErrorMsgs = []string {
63
+ fmt .Sprintf ("failed to parse flags: %s" , err .Error ()),
64
+ }
65
+ return pluginResponse
66
+ }
59
67
domain , _ := flags .GetString ("domain" )
60
68
61
69
initFile := templates .NewInitFile (templates .WithDomain (domain ))
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ limitations under the License.
16
16
package scaffolds
17
17
18
18
import (
19
+ "fmt"
20
+
19
21
"github.com/spf13/pflag"
20
22
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
21
23
"sigs.k8s.io/kubebuilder/v4/pkg/plugin/external"
@@ -52,7 +54,13 @@ func WebhookCmd(pr *external.PluginRequest) external.PluginResponse {
52
54
// Here is an example of parsing a flag from a Kubebuilder external plugin request
53
55
flags := pflag .NewFlagSet ("apiFlags" , pflag .ContinueOnError )
54
56
flags .Bool ("hooked" , false , "add the word `hooked` to the end of the scaffolded webhookFile.txt" )
55
- flags .Parse (pr .Args )
57
+ if err := flags .Parse (pr .Args ); err != nil {
58
+ pluginResponse .Error = true
59
+ pluginResponse .ErrorMsgs = []string {
60
+ fmt .Sprintf ("failed to parse flags: %s" , err .Error ()),
61
+ }
62
+ return pluginResponse
63
+ }
56
64
hooked , _ := flags .GetBool ("hooked" )
57
65
58
66
msg := "A simple text file created with the `create webhook` subcommand"
You can’t perform that action at this time.
0 commit comments