Skip to content

Commit ef10337

Browse files
author
Ish Shah
authored
hack/doc: Autogen CLI Documentation (#2099)
* init structure * makefile updates, compiling * working file tree * updated dir * initial draft of generated docs * update changelog * go mod tidy * add hugo headers to docs * fix md block tree formatting * remove header logic * updated docs * add sanity test * add script * update path * path re-fix * tidy * mod tidy * updated docs * changlog command update * Update hack/doc/gen-cli-doc.go Co-Authored-By: Eric Stroczynski <[email protected]> * Update hack/doc/gen-cli-doc.go Co-Authored-By: Eric Stroczynski <[email protected]> * Update hack/doc/gen-cli-doc.go Co-Authored-By: Eric Stroczynski <[email protected]> * format nits * fmt fix
1 parent bad0ca5 commit ef10337

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1105
-94
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
- Added `Operator Version: X.Y.Z` information in the operator logs.([#1953](https://github.com/operator-framework/operator-sdk/pull/1953))
2020
- Make Ansible verbosity configurable via the `ansible-verbosity` flag. ([#2087](https://github.com/operator-framework/operator-sdk/pull/2087))
21+
- Autogenerate CLI documentation via `make cli-doc` ([#2099](https://github.com/operator-framework/operator-sdk/pull/2099))
2122

2223
### Changed
2324

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ help: ## Show this help screen
4343
all: format test build/operator-sdk ## Test and Build the Operator SDK
4444

4545
# Code management.
46-
.PHONY: test format tidy clean
46+
.PHONY: format tidy clean cli-doc
4747

4848
format: ## Format the source code
4949
$(Q)go fmt $(PKGS)
@@ -54,6 +54,9 @@ tidy: ## Update dependencies
5454
clean: ## Clean up the build artifacts
5555
$(Q)rm -rf build
5656

57+
cli-doc: ## Generate CLI Documentation
58+
./hack/doc/gen_cli_doc.sh
59+
5760
# Build/install/release the SDK.
5861
.PHONY: install release_builds release
5962

cmd/operator-sdk/add/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ is generated as a 'validation' object. Generation can be disabled with the
5555
--skip-generation flag.
5656
5757
Example:
58+
5859
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
5960
$ tree pkg/apis
6061
pkg/apis/

cmd/operator-sdk/add/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This command must be run from the project root directory.
3939
If the controller pkg for that Kind already exists at pkg/controller/<kind> then the command will not overwrite and return an error.
4040
4141
Example:
42+
4243
$ operator-sdk add controller --api-version=app.example.com/v1alpha1 --kind=AppService
4344
$ tree pkg/controller
4445
pkg/controller/

cmd/operator-sdk/build/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This image will be automatically set in the deployment manifests.
4848
After build completes, the image would be built locally in docker. Then it needs to
4949
be pushed to remote registry.
5050
For example:
51+
5152
$ operator-sdk build quay.io/example/operator:v0.0.1
5253
$ docker push quay.io/example/operator:v0.0.1
5354
`,

cmd/operator-sdk/cli/cli.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
19+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
20+
// to ensure that `run` and `up local` can make use of them.
21+
_ "k8s.io/client-go/plugin/pkg/client/auth"
22+
23+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
24+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
25+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
26+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
27+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
28+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
29+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
30+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/olmcatalog"
31+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps"
32+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/run"
33+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard"
34+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/test"
35+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/up"
36+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
37+
"github.com/operator-framework/operator-sdk/internal/flags"
38+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
39+
40+
log "github.com/sirupsen/logrus"
41+
"github.com/spf13/cobra"
42+
"github.com/spf13/viper"
43+
)
44+
45+
// GetCLIRoot is intended to creeate the base command structure for the OSDK for use in CLI and documentation
46+
func GetCLIRoot() *cobra.Command {
47+
root := &cobra.Command{
48+
Use: "operator-sdk",
49+
Short: "An SDK for building operators with ease",
50+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
51+
if viper.GetBool(flags.VerboseOpt) {
52+
if err := projutil.SetGoVerbose(); err != nil {
53+
log.Fatalf("Could not set GOFLAGS: (%v)", err)
54+
}
55+
log.SetLevel(log.DebugLevel)
56+
log.Debug("Debug logging is set")
57+
}
58+
if err := checkGoModulesForCmd(cmd); err != nil {
59+
log.Fatal(err)
60+
}
61+
},
62+
}
63+
64+
root.AddCommand(add.NewCmd())
65+
root.AddCommand(alpha.NewCmd())
66+
root.AddCommand(build.NewCmd())
67+
root.AddCommand(completion.NewCmd())
68+
root.AddCommand(generate.NewCmd())
69+
root.AddCommand(migrate.NewCmd())
70+
root.AddCommand(new.NewCmd())
71+
root.AddCommand(olmcatalog.NewCmd())
72+
root.AddCommand(printdeps.NewCmd())
73+
root.AddCommand(run.NewCmd())
74+
root.AddCommand(scorecard.NewCmd())
75+
root.AddCommand(test.NewCmd())
76+
root.AddCommand(up.NewCmd())
77+
root.AddCommand(version.NewCmd())
78+
79+
return root
80+
}
81+
82+
func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
83+
// Certain commands are able to be run anywhere or handle this check
84+
// differently in their CLI code.
85+
if skipCheckForCmd(cmd) {
86+
return nil
87+
}
88+
// Do not perform this check if the project is non-Go, as they will not
89+
// be using go modules.
90+
if !projutil.IsOperatorGo() {
91+
return nil
92+
}
93+
// Do not perform a go modules check if the working directory is not in
94+
// the project root, as some sub-commands might not require project root.
95+
// Individual subcommands will perform this check as needed.
96+
if err := projutil.CheckProjectRoot(); err != nil {
97+
return nil
98+
}
99+
100+
return projutil.CheckGoModules()
101+
}
102+
103+
var commandsToSkip = map[string]struct{}{
104+
"new": struct{}{}, // Handles this logic in cmd/operator-sdk/new
105+
"migrate": struct{}{}, // Handles this logic in cmd/operator-sdk/migrate
106+
"operator-sdk": struct{}{}, // Alias for "help"
107+
"help": struct{}{},
108+
"completion": struct{}{},
109+
"version": struct{}{},
110+
"print-deps": struct{}{}, // Does not require this logic
111+
}
112+
113+
func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
114+
if _, ok := commandsToSkip[cmd.Name()]; ok {
115+
return true
116+
}
117+
cmd.VisitParents(func(pc *cobra.Command) {
118+
if _, ok := commandsToSkip[pc.Name()]; ok {
119+
// The bare "operator-sdk" command will be checked above.
120+
if pc.Name() != "operator-sdk" {
121+
skip = true
122+
}
123+
}
124+
})
125+
return skip
126+
}

cmd/operator-sdk/generate/k8s.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ specs in pkg/apis/<group>/<version> directories to comply with kube-API
3232
requirements. Go code is generated under
3333
pkg/apis/<group>/<version>/zz_generated.deepcopy.go.
3434
Example:
35+
3536
$ operator-sdk generate k8s
3637
$ tree pkg/apis
3738
pkg/apis/

cmd/operator-sdk/generate/openapi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ deploy/crds/<full group>_<resource>_crd.yaml; OpenAPI V3 validation YAML
3333
is generated as a 'validation' object.
3434
3535
Example:
36+
3637
$ operator-sdk generate openapi
3738
$ tree pkg/apis
3839
pkg/apis/

cmd/operator-sdk/main.go

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -21,60 +21,15 @@ import (
2121
// to ensure that `run` and `up local` can make use of them.
2222
_ "k8s.io/client-go/plugin/pkg/client/auth"
2323

24-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
25-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
26-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
27-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
28-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
29-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
30-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
31-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/olmcatalog"
32-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps"
33-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/run"
34-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard"
35-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/test"
36-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/up"
37-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
24+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
3825
"github.com/operator-framework/operator-sdk/internal/flags"
39-
"github.com/operator-framework/operator-sdk/internal/util/projutil"
4026

4127
log "github.com/sirupsen/logrus"
42-
"github.com/spf13/cobra"
4328
"github.com/spf13/viper"
4429
)
4530

4631
func main() {
47-
root := &cobra.Command{
48-
Use: "operator-sdk",
49-
Short: "An SDK for building operators with ease",
50-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
51-
if viper.GetBool(flags.VerboseOpt) {
52-
if err := projutil.SetGoVerbose(); err != nil {
53-
log.Fatalf("Could not set GOFLAGS: (%v)", err)
54-
}
55-
log.SetLevel(log.DebugLevel)
56-
log.Debug("Debug logging is set")
57-
}
58-
if err := checkGoModulesForCmd(cmd); err != nil {
59-
log.Fatal(err)
60-
}
61-
},
62-
}
63-
64-
root.AddCommand(add.NewCmd())
65-
root.AddCommand(alpha.NewCmd())
66-
root.AddCommand(build.NewCmd())
67-
root.AddCommand(completion.NewCmd())
68-
root.AddCommand(generate.NewCmd())
69-
root.AddCommand(migrate.NewCmd())
70-
root.AddCommand(new.NewCmd())
71-
root.AddCommand(olmcatalog.NewCmd())
72-
root.AddCommand(printdeps.NewCmd())
73-
root.AddCommand(run.NewCmd())
74-
root.AddCommand(scorecard.NewCmd())
75-
root.AddCommand(test.NewCmd())
76-
root.AddCommand(up.NewCmd())
77-
root.AddCommand(version.NewCmd())
32+
root := cli.GetCLIRoot()
7833

7934
root.PersistentFlags().Bool(flags.VerboseOpt, false, "Enable verbose logging")
8035
if err := viper.BindPFlags(root.PersistentFlags()); err != nil {
@@ -85,49 +40,3 @@ func main() {
8540
os.Exit(1)
8641
}
8742
}
88-
89-
func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
90-
// Certain commands are able to be run anywhere or handle this check
91-
// differently in their CLI code.
92-
if skipCheckForCmd(cmd) {
93-
return nil
94-
}
95-
// Do not perform this check if the project is non-Go, as they will not
96-
// be using go modules.
97-
if !projutil.IsOperatorGo() {
98-
return nil
99-
}
100-
// Do not perform a go modules check if the working directory is not in
101-
// the project root, as some sub-commands might not require project root.
102-
// Individual subcommands will perform this check as needed.
103-
if err := projutil.CheckProjectRoot(); err != nil {
104-
return nil
105-
}
106-
107-
return projutil.CheckGoModules()
108-
}
109-
110-
var commandsToSkip = map[string]struct{}{
111-
"new": struct{}{}, // Handles this logic in cmd/operator-sdk/new
112-
"migrate": struct{}{}, // Handles this logic in cmd/operator-sdk/migrate
113-
"operator-sdk": struct{}{}, // Alias for "help"
114-
"help": struct{}{},
115-
"completion": struct{}{},
116-
"version": struct{}{},
117-
"print-deps": struct{}{}, // Does not require this logic
118-
}
119-
120-
func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
121-
if _, ok := commandsToSkip[cmd.Name()]; ok {
122-
return true
123-
}
124-
cmd.VisitParents(func(pc *cobra.Command) {
125-
if _, ok := commandsToSkip[pc.Name()]; ok {
126-
// The bare "operator-sdk" command will be checked above.
127-
if pc.Name() != "operator-sdk" {
128-
skip = true
129-
}
130-
}
131-
})
132-
return skip
133-
}

cmd/operator-sdk/new/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ generates a default directory layout based on the input <project-name>.
4545
<project-name> is the project name of the new operator. (e.g app-operator)
4646
4747
For example:
48+
4849
$ mkdir $HOME/projects/example.com/
4950
$ cd $HOME/projects/example.com/
5051
$ operator-sdk new app-operator

doc/cli/operator-sdk.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## operator-sdk
2+
3+
An SDK for building operators with ease
4+
5+
### Synopsis
6+
7+
An SDK for building operators with ease
8+
9+
### Options
10+
11+
```
12+
-h, --help help for operator-sdk
13+
```
14+
15+
### SEE ALSO
16+
17+
* [operator-sdk add](operator-sdk_add.md) - Adds a controller or resource to the project
18+
* [operator-sdk alpha](operator-sdk_alpha.md) - Run an alpha subcommand
19+
* [operator-sdk build](operator-sdk_build.md) - Compiles code and builds artifacts
20+
* [operator-sdk completion](operator-sdk_completion.md) - Generators for shell completions
21+
* [operator-sdk generate](operator-sdk_generate.md) - Invokes specific generator
22+
* [operator-sdk migrate](operator-sdk_migrate.md) - Adds source code to an operator
23+
* [operator-sdk new](operator-sdk_new.md) - Creates a new operator application
24+
* [operator-sdk olm-catalog](operator-sdk_olm-catalog.md) - Invokes a olm-catalog command
25+
* [operator-sdk print-deps](operator-sdk_print-deps.md) - Print Golang packages and versions required to run the operator
26+
* [operator-sdk run](operator-sdk_run.md) - Runs a generic operator
27+
* [operator-sdk scorecard](operator-sdk_scorecard.md) - Run scorecard tests
28+
* [operator-sdk test](operator-sdk_test.md) - Tests the operator
29+
* [operator-sdk up](operator-sdk_up.md) - Launches the operator
30+
* [operator-sdk version](operator-sdk_version.md) - Prints the version of operator-sdk
31+
32+
###### Auto generated by spf13/cobra on 6-Nov-2019

doc/cli/operator-sdk_add.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## operator-sdk add
2+
3+
Adds a controller or resource to the project
4+
5+
### Synopsis
6+
7+
Adds a controller or resource to the project
8+
9+
### Options
10+
11+
```
12+
-h, --help help for add
13+
```
14+
15+
### SEE ALSO
16+
17+
* [operator-sdk](operator-sdk.md) - An SDK for building operators with ease
18+
* [operator-sdk add api](operator-sdk_add_api.md) - Adds a new api definition under pkg/apis
19+
* [operator-sdk add controller](operator-sdk_add_controller.md) - Adds a new controller pkg
20+
* [operator-sdk add crd](operator-sdk_add_crd.md) - Adds a Custom Resource Definition (CRD) and the Custom Resource (CR) files
21+
22+
###### Auto generated by spf13/cobra on 6-Nov-2019

0 commit comments

Comments
 (0)