|
| 1 | +// Copyright 2025 The Operator-SDK Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package scaffold |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "log" |
| 20 | + "runtime" |
| 21 | + |
| 22 | + "github.com/operator-framework/ansible-operator-plugins/pkg/plugins/ansible/v1" |
| 23 | + "github.com/spf13/cobra" |
| 24 | + |
| 25 | + ver "github.com/operator-framework/ansible-operator-plugins/internal/version" |
| 26 | + "sigs.k8s.io/kubebuilder/v4/pkg/cli" |
| 27 | + cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3" |
| 28 | + "sigs.k8s.io/kubebuilder/v4/pkg/plugin" |
| 29 | + kustomizev2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2" |
| 30 | +) |
| 31 | + |
| 32 | +func NewCmd() *cobra.Command { |
| 33 | + cli := GetPluginsCLI() |
| 34 | + return cli.Command() |
| 35 | +} |
| 36 | + |
| 37 | +func GetPluginsCLI() *cli.CLI { |
| 38 | + ansibleBundle, _ := plugin.NewBundleWithOptions( |
| 39 | + plugin.WithName(ansible.Plugin{}.Name()), |
| 40 | + plugin.WithVersion(ansible.Plugin{}.Version()), |
| 41 | + plugin.WithPlugins( |
| 42 | + kustomizev2.Plugin{}, |
| 43 | + ansible.Plugin{}, |
| 44 | + ), |
| 45 | + ) |
| 46 | + |
| 47 | + c, err := cli.New( |
| 48 | + cli.WithCommandName("scaffold"), |
| 49 | + cli.WithDescription("scaffolds ansible-operator"), |
| 50 | + cli.WithVersion(makeVersionString()), |
| 51 | + cli.WithPlugins( |
| 52 | + ansibleBundle, |
| 53 | + ), |
| 54 | + cli.WithDefaultPlugins(cfgv3.Version, ansibleBundle), |
| 55 | + cli.WithDefaultProjectVersion(cfgv3.Version), |
| 56 | + cli.WithCompletion(), |
| 57 | + ) |
| 58 | + |
| 59 | + if err != nil { |
| 60 | + log.Fatal(err) |
| 61 | + } |
| 62 | + |
| 63 | + return c |
| 64 | +} |
| 65 | + |
| 66 | +func makeVersionString() string { |
| 67 | + return fmt.Sprintf("scaffold version: %q, commit: %q, kubernetes version: %q, go version: %q, GOOS: %q, GOARCH: %q", |
| 68 | + ver.GitVersion, ver.GitCommit, ver.KubernetesVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH) |
| 69 | +} |
0 commit comments