-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: example builder utility (#223)
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package examplebuilder | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCmdExample adds example with description to the cobra.Command | ||
func NewCmdExample(cmd *cobra.Command, description string, flags []string) { | ||
cmd.Example += fmt.Sprintf("\n\n# %s \n%s %s", description, cmd.CommandPath(), strings.Join(flags, ", ")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Charmil Utils | ||
slug: /charmil_utils | ||
--- | ||
|
||
## Example Builder | ||
Example Builder provides Example string builder which generates full example string of the cobra command and append to existing examples. | ||
|
||
NewCmdExample function accepts a cobra command in which example needs to be generated, description of the command and a slice of flags(if any) | ||
|
||
```go | ||
examplebuilder.NewCmdExample(cmd, "List all artifacts for the default artifacts group", []string{"list --page=4"}) | ||
examplebuilder.NewCmdExample(cmd, "List all artifacts", []string{"list"}) | ||
``` | ||
|
||
Output | ||
```bash | ||
Examples: | ||
|
||
# List all artifacts for the default artifacts group | ||
kafka list --page=4 | ||
|
||
# List all artifacts | ||
kafka list | ||
``` |