Skip to content

Commit

Permalink
Merge pull request #1828 from Adirio/cli-refactoring
Browse files Browse the repository at this point in the history
⚠ pkg/cli overhaul
  • Loading branch information
pwittrock committed Dec 4, 2020
2 parents 6b775b8 + cb369d9 commit 593f2e8
Show file tree
Hide file tree
Showing 19 changed files with 1,427 additions and 894 deletions.
7 changes: 6 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"

"sigs.k8s.io/kubebuilder/v2/pkg/cli"
"sigs.k8s.io/kubebuilder/v2/pkg/model/config"
pluginv2 "sigs.k8s.io/kubebuilder/v2/pkg/plugins/golang/v2"
pluginv3 "sigs.k8s.io/kubebuilder/v2/pkg/plugins/golang/v3"
)
Expand All @@ -28,11 +29,15 @@ func main() {
c, err := cli.New(
cli.WithCommandName("kubebuilder"),
cli.WithVersion(versionString()),
cli.WithDefaultProjectVersion(config.Version3Alpha),
cli.WithPlugins(
&pluginv2.Plugin{},
&pluginv3.Plugin{},
),
cli.WithDefaultPlugins(
cli.WithDefaultPlugins(config.Version2,
&pluginv2.Plugin{},
),
cli.WithDefaultPlugins(config.Version3Alpha,
&pluginv2.Plugin{},
),
cli.WithCompletion,
Expand Down
16 changes: 8 additions & 8 deletions pkg/cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sigs.k8s.io/kubebuilder/v2/pkg/plugin"
)

func (c *cli) newCreateAPICmd() *cobra.Command {
func (c cli) newCreateAPICmd() *cobra.Command {
ctx := c.newAPIContext()
cmd := &cobra.Command{
Use: "api",
Expand All @@ -43,19 +43,20 @@ func (c *cli) newCreateAPICmd() *cobra.Command {
}

func (c cli) newAPIContext() plugin.Context {
ctx := plugin.Context{
return plugin.Context{
CommandName: c.commandName,
Description: `Scaffold a Kubernetes API.
`,
}
if !c.configured {
ctx.Description = fmt.Sprintf("%s\n%s", ctx.Description, runInProjectRootMsg)
}
return ctx
}

// nolint:dupl
func (c cli) bindCreateAPI(ctx plugin.Context, cmd *cobra.Command) {
if len(c.resolvedPlugins) == 0 {
cmdErr(cmd, fmt.Errorf(noPluginError))
return
}

var createAPIPlugin plugin.CreateAPI
for _, p := range c.resolvedPlugins {
tmpPlugin, isValid := p.(plugin.CreateAPI)
Expand All @@ -71,8 +72,7 @@ func (c cli) bindCreateAPI(ctx plugin.Context, cmd *cobra.Command) {
}

if createAPIPlugin == nil {
err := fmt.Errorf("relevant plugins do not provide an API creation plugin")
cmdErr(cmd, err)
cmdErr(cmd, fmt.Errorf("resolved plugins do not provide an API creation plugin: %v", c.pluginKeys))
return
}

Expand Down
Loading

0 comments on commit 593f2e8

Please sign in to comment.