Skip to content

Commit 2d0bae4

Browse files
authored
Merge pull request #2105 from Adirio/cli-description
✨ Allow to modify the root's command description
2 parents e3437d6 + d7bd9c7 commit 2d0bae4

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

pkg/cli/cli.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type CLI struct { //nolint:maligned
4848
commandName string
4949
// CLI version string.
5050
version string
51+
// CLI root's command description.
52+
description string
5153
// Plugins registered in the CLI.
5254
plugins map[string]plugin.Plugin
5355
// Default plugins in case none is provided and a config file can't be found.
@@ -120,7 +122,9 @@ func New(options ...Option) (*CLI, error) {
120122
func newCLI(options ...Option) (*CLI, error) {
121123
// Default CLI options.
122124
c := &CLI{
123-
commandName: "kubebuilder",
125+
commandName: "kubebuilder",
126+
description: `CLI tool for building Kubernetes extensions and tools.
127+
`,
124128
plugins: make(map[string]plugin.Plugin),
125129
defaultPlugins: make(map[config.Version][]string),
126130
fs: machinery.Filesystem{FS: afero.NewOsFs()},

pkg/cli/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func WithVersion(version string) Option {
4444
}
4545
}
4646

47+
// WithDescription is an Option that sets the CLI's root description.
48+
func WithDescription(description string) Option {
49+
return func(c *CLI) error {
50+
c.description = description
51+
return nil
52+
}
53+
}
54+
4755
// WithPlugins is an Option that sets the CLI's plugins.
4856
//
4957
// Specifying any invalid plugin results in an error.

pkg/cli/options_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ var _ = Describe("CLI options", func() {
6767
})
6868
})
6969

70+
Context("WithDescription", func() {
71+
It("should use the provided description string", func() {
72+
description := "alternative description"
73+
c, err = newCLI(WithDescription(description))
74+
Expect(err).NotTo(HaveOccurred())
75+
Expect(c).NotTo(BeNil())
76+
Expect(c.description).To(Equal(description))
77+
})
78+
})
79+
7080
Context("WithPlugins", func() {
7181
It("should return a valid CLI", func() {
7282
c, err = newCLI(WithPlugins(p))

pkg/cli/root.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ const (
3131

3232
func (c CLI) newRootCmd() *cobra.Command {
3333
cmd := &cobra.Command{
34-
Use: c.commandName,
35-
Long: `CLI tool for building Kubernetes extensions and tools.
36-
`,
34+
Use: c.commandName,
35+
Long: c.description,
3736
Example: c.rootExamples(),
3837
RunE: func(cmd *cobra.Command, args []string) error {
3938
return cmd.Help()

0 commit comments

Comments
 (0)