Skip to content

Commit 04c00f6

Browse files
committed
Create structure for long descriptions and examples
1 parent 1ce879d commit 04c00f6

File tree

9 files changed

+133
-13
lines changed

9 files changed

+133
-13
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ dryinstall: go-build
3535

3636
.PHONY: install
3737
install: uninstall go-build
38-
@sudo mkdir ~/.$(BINARY_NAME) -p
39-
@sudo mkdir ~/.$(BINARY_NAME)/config -p
40-
@sudo mkdir ~/.$(BINARY_NAME)/profiles -p
38+
@sudo mkdir -p ~/.$(BINARY_NAME)
39+
@sudo mkdir -p ~/.$(BINARY_NAME)/config
40+
@sudo mkdir -p ~/.$(BINARY_NAME)/profiles
4141
@sudo cp ./tests/config.json ~/.$(BINARY_NAME)/config/config.json
4242
@sudo mv $(SOURCE_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
4343
@sudo chmod -R 777 ~/.$(BINARY_NAME)
4444
@echo "$(BINARY_NAME) installed..!"
4545
@echo
46-
make clean
46+
@$(MAKE) clean

src/cmd/create/flink_cluster.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ var (
2323
replicas uint8 = 1
2424
)
2525

26+
// Description and Examples for creating flink clsuters
27+
var (
28+
flinkLongDesc = utils.LongDesc(`
29+
Create a flink cluster with specified requirments.
30+
`)
31+
)
32+
2633
// infoCmd represents the info command
2734
var FlinkClusterCmd = &cobra.Command{
2835
Use: "flink-cluster",
2936
Short: "create a flink cluster",
30-
Long: `create a flink cluster`,
37+
Long: flinkLongDesc,
3138
Args: cobra.ExactArgs(1),
3239
Run: func(cmd *cobra.Command, args []string) {
3340
profile, err := utils.ValidateCluster()

src/cmd/deploy/pipeline.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import (
2424
"k8s.io/client-go/rest"
2525
)
2626

27+
var (
28+
deployLongDesc = utils.LongDesc(`
29+
Deploy an Apache Beam pipeline on a specified Operator.
30+
`)
31+
)
32+
2733
var (
2834
flinkCluster string = ""
2935
PVCMountPath string = "/pvc"
@@ -45,7 +51,7 @@ type FileInfo struct {
4551
var PipelineCmd = &cobra.Command{
4652
Use: "pipeline [FILE]",
4753
Short: "Deploy an Apache Beam pipeline",
48-
Long: "Deploy an Apache Beam pipeline on a specified Operator.",
54+
Long: deployLongDesc,
4955
Args: cobra.ExactArgs(1),
5056
Run: DeployPipeline,
5157
}

src/cmd/info/cluster.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ import (
55
"time"
66

77
info_handler "github.com/BeamStackProj/beamstack-cli/src/handlers/info"
8+
"github.com/BeamStackProj/beamstack-cli/src/utils"
89
"github.com/spf13/cobra"
910
v1 "k8s.io/api/core/v1"
1011
)
1112

13+
var (
14+
clusterLongDesc = utils.LongDesc(`
15+
This command fetches detailed information about the Kubernetes cluster,
16+
including the status of each node and the overall health of the cluster.
17+
`)
18+
19+
clusterExample = utils.Examples(`
20+
# Get cluster information
21+
beamstack info cluster
22+
`)
23+
)
24+
1225
// infoCmd represents the info command
1326
var ClusterCmd = &cobra.Command{
14-
Use: "cluster",
15-
Short: "get information the kubernetes cluster",
16-
Long: `Cluster information including nodes, and current workloads`,
27+
Use: "cluster",
28+
Short: "get information the kubernetes cluster",
29+
Long: clusterLongDesc,
30+
Example: clusterExample,
1731
Run: func(cmd *cobra.Command, args []string) {
1832
clusterHealth, err := info_handler.Health()
1933

src/cmd/info/info.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ import (
1111
"github.com/spf13/viper"
1212
)
1313

14+
// Long Description and Example initizalization
15+
var (
16+
infoLongDesc = utils.LongDesc(`
17+
This command displays detailed information about specified resources such as clusters.
18+
`)
19+
)
20+
1421
// infoCmd represents the info command
1522
var InfoCmd = &cobra.Command{
1623
Use: "info",
1724
Short: "Pallete that contains information based commands",
18-
Long: `Pallete that contains information based commands`,
25+
Long: infoLongDesc,
1926
Run: func(cmd *cobra.Command, args []string) {
2027
ctx, err := utils.GetCurrentContext()
2128
if err != nil {

src/cmd/initialize/init.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ import (
1212
"github.com/spf13/viper"
1313
)
1414

15+
var (
16+
initLongDesc = utils.LongDesc(`
17+
Initialize Beamstack in a new Kubernetes environment, setting up essential configurations and prerequisites.
18+
`)
19+
)
20+
1521
var InitCmd = &cobra.Command{
1622
Use: "init",
1723
Short: "Initialize beamstack on cluster",
18-
Long: `Initialize Beamstack in a new Kubernetes environment, setting up essential configurations and prerequisites.`,
24+
Long: initLongDesc,
1925
Run: runInit,
2026
}
2127

src/cmd/open/dashboard.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ import (
1616
"k8s.io/client-go/kubernetes"
1717
)
1818

19+
// Description and Examples for opening grafana dashboard
20+
var (
21+
openDashboardLongDesc = utils.LongDesc(`
22+
This command opens up the GUI for the Grafana Dashbaord.
23+
`)
24+
)
25+
1926
// infoCmd represents the info command
2027
var DashboardCmd = &cobra.Command{
2128
Use: "dashboard",
2229
Short: "opens up grafana dashboard",
23-
Long: `opens up grafana dashboard`,
30+
Long: openDashboardLongDesc,
2431
Run: func(cmd *cobra.Command, args []string) {
2532
LocalPort, err := cmd.Flags().GetUint16("localport")
2633
if err != nil {

src/cmd/open/flink_cluster.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ import (
1616
"k8s.io/client-go/kubernetes"
1717
)
1818

19+
// Description and Examples for opening grafana dashboard
20+
var (
21+
openFlinkClusterLongDesc = utils.LongDesc(`
22+
This command opens up the GUI for the flink clusters and forward it to a specified local port.
23+
`)
24+
)
25+
1926
// infoCmd represents the info command
2027
var FlinkClusterCmd = &cobra.Command{
2128
Use: "flink",
2229
Short: "opens up flink cluster ui",
23-
Long: `opens up flink cluster ui`,
30+
Long: openFlinkClusterLongDesc,
2431
Args: cobra.ExactArgs(1),
2532
Run: func(cmd *cobra.Command, args []string) {
2633
LocalPort, err := cmd.Flags().GetUint16("localport")

src/utils/documentation.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package utils
2+
3+
import (
4+
"strings"
5+
)
6+
7+
var (
8+
// AlphaDisclaimer to be places at the end of description of commands in alpha release
9+
AlphaDisclaimer = `
10+
Alpha Disclaimer: this command is currently alpha.
11+
`
12+
13+
// MacroCommandLongDescription provide a standard description for "macro" commands
14+
MacroCommandLongDescription = LongDesc(`
15+
This command is not meant to be run on its own. See list of available subcommands.
16+
`)
17+
)
18+
19+
func LongDesc(s string) string {
20+
// Strip beginning and trailing space characters (including empty lines) and split the lines into a slice
21+
lines := strings.Split(strings.TrimSpace(s), "\n")
22+
23+
output := []string{}
24+
paragraph := []string{}
25+
26+
for _, line := range lines {
27+
// Remove indentation and trailing spaces from the current line
28+
trimmedLine := strings.TrimSpace(line)
29+
if trimmedLine == "" {
30+
if len(paragraph) > 0 {
31+
output = append(output, strings.Join(paragraph, " ")+"\n")
32+
paragraph = []string{}
33+
}
34+
} else {
35+
// Non-empty text line, append it to the current paragraph
36+
paragraph = append(paragraph, trimmedLine)
37+
if strings.HasSuffix(line, " ") {
38+
output = append(output, strings.Join(paragraph, " "))
39+
paragraph = []string{}
40+
}
41+
}
42+
}
43+
44+
output = append(output, strings.Join(paragraph, " "))
45+
46+
// Join all the paragraphs together with new lines in between them.
47+
return strings.Join(output, "\n")
48+
}
49+
50+
// Examples is designed to help with producing examples for command line usage.
51+
func Examples(s string) string {
52+
trimmedText := strings.TrimSpace(s)
53+
if trimmedText == "" {
54+
return ""
55+
}
56+
57+
const indent = ` `
58+
inLines := strings.Split(trimmedText, "\n")
59+
outLines := make([]string, 0, len(inLines))
60+
61+
for _, line := range inLines {
62+
outLines = append(outLines, indent+strings.TrimSpace(line))
63+
}
64+
65+
return strings.Join(outLines, "\n")
66+
}

0 commit comments

Comments
 (0)