Skip to content

Commit 3229902

Browse files
committed
fix(docs): Add synopsis for bind apiservice and preserve list formatting
Signed-off-by: olalekan odukoya <odukoyaonline@gmail.com>
1 parent 70f7ece commit 3229902

3 files changed

Lines changed: 72 additions & 21 deletions

File tree

cli/pkg/help/help.go

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package help
1818

1919
import (
2020
"io"
21-
"regexp"
2221
"strings"
2322
"unicode"
2423

@@ -28,12 +27,45 @@ import (
2827
"k8s.io/component-base/term"
2928
)
3029

31-
var reEmptyLine = regexp.MustCompile(`(?m)([\w[:punct:]])[ ]*\n([\w[:punct:]])`)
32-
3330
func Doc(s string) string {
3431
s = heredoc.Doc(s)
35-
s = reEmptyLine.ReplaceAllString(s, "$1 $2")
36-
return s
32+
33+
lines := strings.Split(s, "\n")
34+
result := make([]string, 0, len(lines))
35+
36+
for i, line := range lines {
37+
trimmed := strings.TrimSpace(line)
38+
39+
if isListItem(line) {
40+
result = append(result, line)
41+
continue
42+
}
43+
44+
if trimmed == "" && i < len(lines)-1 && isListItem(lines[i+1]) {
45+
result = append(result, line)
46+
continue
47+
}
48+
49+
if len(result) > 0 && trimmed != "" {
50+
prevLine := result[len(result)-1]
51+
prevTrimmed := strings.TrimSpace(prevLine)
52+
53+
if prevTrimmed != "" && !isListItem(prevLine) {
54+
if i > 0 && strings.TrimSpace(lines[i-1]) == "" {
55+
if i < len(lines)-1 && isListItem(lines[i+1]) {
56+
result = append(result, line)
57+
continue
58+
}
59+
result[len(result)-1] = prevLine + " " + trimmed
60+
continue
61+
}
62+
}
63+
}
64+
65+
result = append(result, line)
66+
}
67+
68+
return strings.Join(result, "\n")
3769
}
3870

3971
func FitTerminal(out io.Writer) {
@@ -46,3 +78,10 @@ func FitTerminal(out io.Writer) {
4678
return strings.TrimRightFunc(wordwrap.String(s, cols), unicode.IsSpace)
4779
})
4880
}
81+
82+
func isListItem(line string) bool {
83+
trimmed := strings.TrimSpace(line)
84+
return strings.HasPrefix(trimmed, "-") ||
85+
strings.HasPrefix(trimmed, "*") ||
86+
strings.HasPrefix(trimmed, "+")
87+
}

cli/pkg/kubectl/bind-apiservice/cmd/cmd.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"k8s.io/cli-runtime/pkg/genericclioptions"
2525
logsv1 "k8s.io/component-base/logs/api/v1"
2626

27+
"github.com/kube-bind/kube-bind/cli/pkg/help"
2728
"github.com/kube-bind/kube-bind/cli/pkg/kubectl/bind-apiservice/plugin"
2829

2930
_ "k8s.io/client-go/plugin/pkg/client/auth/exec"
@@ -43,8 +44,19 @@ var (
4344
func New(streams genericclioptions.IOStreams) (*cobra.Command, error) {
4445
opts := plugin.NewBindAPIServiceOptions(streams)
4546
cmd := &cobra.Command{
46-
Use: "apiservice https://<url-to-a-APIServiceExportRequest>|-f <file-to-a-APIBindingRequest>",
47-
Short: "Bind to a remote API service",
47+
Use: "apiservice https://<url-to-a-APIServiceExportRequest>|-f <file-to-a-APIBindingRequest>",
48+
Short: "Bind to a remote API service",
49+
Long: help.Doc(`Bind to a remote API service by creating an APIServiceExportRequest.
50+
51+
This command allows you to bind remote services into your cluster by either:
52+
53+
- Providing a URL to an APIServiceExportRequest resource
54+
- Providing a file containing an APIServiceExportRequest manifest
55+
- Using a template name to interactively create the binding
56+
57+
The command will authenticate with the remote service provider, create the necessary
58+
APIServiceExportRequest, and deploy a konnector to establish the connection between
59+
your cluster and the remote service.`),
4860
Example: fmt.Sprintf(bindAPIServiceExampleUses, "kubectl bind"),
4961
SilenceUsage: true,
5062
RunE: func(cmd *cobra.Command, args []string) error {

cli/pkg/kubectl/dev/cmd/cmd.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ func newInitCommand(streams genericclioptions.IOStreams) (*cobra.Command, error)
8888
cmd := &cobra.Command{
8989
Use: "create",
9090
Short: "Create development environment with kind cluster and kube-bind backend",
91-
Long: help.Doc(`
92-
Create a complete development environment for kube-bind using kind clusters.
93-
94-
This command will:
95-
- Create a kind cluster configured for kube-bind development
96-
- Add kube-bind.dev.local to /etc/hosts (with sudo prompts if needed)
97-
- Install kube-bind backend helm chart (default: OCI chart from ghcr.io)
98-
- Configure necessary port mappings (8443, 15021)
99-
100-
The backend chart can be sourced from:
101-
- OCI registry (default): oci://ghcr.io/kube-bind/charts/backend
102-
- Local filesystem: --chart-path ./deploy/charts/backend
103-
- Custom OCI registry: --chart-path oci://custom.registry/charts/backend
104-
`),
91+
Long: help.Doc(`Create a complete development environment for kube-bind using kind clusters.
92+
93+
This command will:
94+
95+
- Create a kind cluster configured for kube-bind developmentls
96+
- Add kube-bind.dev.local to /etc/hosts (with sudo prompts if needed)
97+
- Install kube-bind backend helm chart (default: OCI chart from ghcr.io)
98+
- Configure necessary port mappings (8443, 15021)
99+
100+
The backend chart can be sourced from:xw
101+
102+
- OCI registry (default): oci://ghcr.io/kube-bind/charts/backend
103+
- Local filesystem: --chart-path ./deploy/charts/backend
104+
- Custom OCI registry: --chart-path oci://custom.registry/charts/backend`),
105105
Example: fmt.Sprintf(DevCreateExampleUses, "kubectl bind dev"),
106106
SilenceUsage: true,
107107
Args: cobra.NoArgs,

0 commit comments

Comments
 (0)