Skip to content

Commit 2a34a5b

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #874 from SoftLayer/issues873
Added a doc builder to buildAndDeploy, …
2 parents 87f6ed4 + 74bc7e8 commit 2a34a5b

File tree

6 files changed

+63
-10
lines changed

6 files changed

+63
-10
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,16 @@ ALSO:
467467
## CLI Documentation
468468
To make changes to the cli documentation, do so here: https://github.ibm.com/cloud-docs/cli/tree/draft/reference/ibmcloud
469469
470+
Docs for the `sl` plugin specifically live in this repo: https://github.ibm.com/cloud-docs/cli
471+
472+
in `docs/` there is a utility that will generate the appropriate pages for the sl plugin.
473+
474+
(assuming `~/Code/ibm-cloud-docs-cl` is where the cloud-docs have been checked out to.)
475+
```
476+
./bin/buildAndDeploy.py docs ~/Code/ibm-cloud-docs-cli
477+
Building documentation builder: go build -o docBuilder docs/main.go
478+
Building documentation: ./docBuilder -o C:/Users/allmi/Code/ibm-cloud-docs-cli/_include-segments -v
479+
```
470480
471481
# Code Patterns
472482

bin/buildAndDeploy.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ def goBuild(self, theOs: str, theArch: str) -> None:
321321
# This command basically requires shell=True on mac because -ldflags doesn't get parsed properly withoutit.
322322
subprocess.run(buildCmd, shell=True)
323323

324+
def buildDocs(self, out_path: str) -> None:
325+
"""Generates the IBM Cloud CLI Documentation
326+
327+
:param str out_path: location of https://github.ibm.com/cloud-docs/cli repositry
328+
"""
329+
330+
# Step 1, build the builder:
331+
buildCmd = f" go build -o docBuilder docs/main.go"
332+
print(f"[turquoise2] Building documentation builder: {buildCmd}")
333+
subprocess.run(buildCmd, shell=True)
334+
335+
# Check if out_dir is good:
336+
if os.path.isdir(f"{out_path}/_include-segments") == False:
337+
raise Exception(f"{out_path}/_include-segments does not exist, or not reachable from {self.cwd}")
338+
339+
docsCmd = f"./docBuilder -o {out_path}/_include-segments -v"
340+
print(f"[turquoise2] Building documentation: {docsCmd}")
341+
subprocess.run(docsCmd)
342+
324343
@click.group()
325344
@click.pass_context
326345
def cli(ctx):
@@ -379,6 +398,17 @@ def i18n(ctx):
379398
runI18n4go(ctx.obj.getdir())
380399
# genBinData()
381400

401+
@cli.command()
402+
@click.argument("out_path")
403+
@click.pass_context
404+
def docs(ctx, out_path):
405+
"""Generate the documentation files.
406+
407+
Requires a copy of https://github.ibm.com/cloud-docs/cli checked out.
408+
out_path should point to the root directory of the cli repository.
409+
"""
410+
ctx.obj.buildDocs(out_path)
411+
382412
if __name__ == '__main__':
383413
cli()
384414
# try:

docs/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
)
1717

1818
var fileName string
19+
var outputPath string
20+
var debug bool
1921
var rootCmd = &cobra.Command{
2022
Use: "doc-gen",
2123
Short: "Generate the documentation for the sl plugin",
@@ -25,7 +27,10 @@ var rootCmd = &cobra.Command{
2527
},
2628
}
2729

30+
2831
func main() {
32+
rootCmd.Flags().StringVarP(&outputPath, "output", "o", "./docs", "Output path, default to ./docs .")
33+
rootCmd.Flags().BoolVarP(&debug, "verbose", "v", false, "Enable Debug logging.")
2934
err := rootCmd.Execute()
3035
checkError(err)
3136
return
@@ -84,6 +89,7 @@ func CliDocs() {
8489
// This is a single command, like 'call-api' and doesn't have sub-commands
8590
thisCmdGroup.Commands = []SlCmdDoc{cobraToSl(iCmd, "")}
8691
}
92+
printDebug(fmt.Sprintf("Working on command group %s\n", shortName))
8793
PrintMakrdown(thisCmdGroup)
8894
CmdGroups = append(CmdGroups, thisCmdGroup)
8995
}
@@ -121,7 +127,8 @@ ibmcloud {{.Use}}
121127

122128
mdTemplate, err := template.New("cmd template").Parse(cmdTemplate)
123129
checkError(err)
124-
filename := fmt.Sprintf("%v.md", cmd.CommandShortLink)
130+
filename := fmt.Sprintf("%s/%v.md", outputPath, cmd.CommandShortLink)
131+
printDebug(fmt.Sprintf("\tCreating file %s\n", filename))
125132
outfile, err := os.Create(filename) //#nosec G304 -- This is a false positive
126133
defer outfile.Close()
127134
err = mdTemplate.Execute(outfile, cmd)
@@ -201,3 +208,9 @@ func buildSlCmdFlag(topCommand *cobra.Command) []SlCmdFlag {
201208
})
202209
return flags
203210
}
211+
212+
func printDebug(output string) {
213+
if debug {
214+
fmt.Printf(output)
215+
}
216+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ require (
1010
github.com/nicksnyder/go-i18n/v2 v2.4.0
1111
github.com/onsi/ginkgo/v2 v2.17.1
1212
github.com/onsi/gomega v1.33.0
13-
github.com/softlayer/softlayer-go v1.1.5
13+
github.com/sethvargo/go-password v0.3.1
14+
github.com/softlayer/softlayer-go v1.1.6
1415
github.com/spf13/cobra v1.8.1
1516
github.com/spf13/pflag v1.0.5
1617
github.com/stretchr/testify v1.9.0
@@ -34,7 +35,6 @@ require (
3435
github.com/pmezard/go-difflib v1.0.0 // indirect
3536
github.com/rivo/uniseg v0.4.7 // indirect
3637
github.com/rogpeppe/go-internal v1.9.0 // indirect
37-
github.com/sethvargo/go-password v0.3.1 // indirect
3838
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect
3939
golang.org/x/crypto v0.24.0 // indirect
4040
golang.org/x/mod v0.18.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
7272
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
7373
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
7474
github.com/smartystreets/goconvey v1.6.7/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
75-
github.com/softlayer/softlayer-go v1.1.5 h1:UFFtgKxiw0yIuUw93XBCFIiIMYR5eLgmm4a5DqMHXGg=
76-
github.com/softlayer/softlayer-go v1.1.5/go.mod h1:WeJrBLoTJcaT8nO1azeyHyNpo/fDLtbpbvh+pzts+Qw=
75+
github.com/softlayer/softlayer-go v1.1.6 h1:VRNXiXZTpb7cfKjimU5E7W9zzKYzWMr/xtqlJ0pHwkQ=
76+
github.com/softlayer/softlayer-go v1.1.6/go.mod h1:WeJrBLoTJcaT8nO1azeyHyNpo/fDLtbpbvh+pzts+Qw=
7777
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e h1:3OgWYFw7jxCZPcvAg+4R8A50GZ+CCkARF10lxu2qDsQ=
7878
github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e/go.mod h1:fKZCUVdirrxrBpwd9wb+lSoVixvpwAu8eHzbQB2tums=
7979
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=

plugin/commands/user/list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package user
22

33
import (
4-
"fmt"
4+
"sort"
55
"strings"
66

77
"github.com/spf13/cobra"
@@ -51,12 +51,12 @@ func NewListCommand(sl *metadata.SoftlayerCommand) (cmd *ListCommand) {
5151
},
5252
}
5353

54-
columns := ""
54+
columns := []string{}
5555
for key, _ := range maskMap {
56-
columns = fmt.Sprintf("%s %s,", columns, key)
56+
columns = append(columns, key)
5757
}
58-
columns = strings.TrimSuffix(columns, ",")
59-
subs := map[string]interface{}{"Columns": columns}
58+
sort.Strings(columns)
59+
subs := map[string]interface{}{"Columns": strings.Join(columns, ", ")}
6060
cobraCmd.Flags().StringSliceVar(&thisCmd.Column, "column", []string{},
6161
T("Column to display. options are: {{.Columns}}. This option can be specified multiple times", subs))
6262

0 commit comments

Comments
 (0)