Skip to content

Commit

Permalink
Refactor docs generator: add longMD into Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhbert authored and distorhead committed Oct 5, 2022
1 parent 340749f commit 5261f5c
Show file tree
Hide file tree
Showing 31 changed files with 41 additions and 63 deletions.
1 change: 1 addition & 0 deletions cmd/werf/build/main.go
Expand Up @@ -45,6 +45,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(common.WerfDebugAnsibleArgs),
common.DocsLongMD: GetBuildDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/bundle/export/export.go
Expand Up @@ -47,6 +47,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(),
common.DocsLongMD: GetBundleExportDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/bundle/publish/publish.go
Expand Up @@ -49,6 +49,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(),
common.DocsLongMD: GetBundlePublishDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
3 changes: 3 additions & 0 deletions cmd/werf/cleanup/cleanup.go
Expand Up @@ -36,6 +36,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
Short: "Cleanup project images in the container registry",
Long: common.GetLongCommandDescription(GetCleanupDocs().Long),
Example: ` $ werf cleanup --repo registry.mydomain.com/myproject/werf`,
Annotations: map[string]string{
common.DocsLongMD: GetCleanupDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

Expand Down
4 changes: 3 additions & 1 deletion cmd/werf/common/envs.go
Expand Up @@ -14,14 +14,16 @@ const (
CmdEnvAnno string = "environment"
DisableOptionsInUseLineAnno string = "disableOptionsInUseLine"

DocsLongMD string = "docsLongMD"

WerfDebugAnsibleArgs Env = "WERF_DEBUG_ANSIBLE_ARGS"
WerfSecretKey Env = "WERF_SECRET_KEY"
WerfOldSecretKey Env = "WERF_OLD_SECRET_KEY"
)

var envDescription = map[Env]string{
WerfDebugAnsibleArgs: "Pass specified cli args to ansible ($ANSIBLE_ARGS)",
WerfSecretKey: `Use specified secret key to extract secrets for the deploy. Recommended way to set secret key in CI-system.
WerfSecretKey: `Use specified secret key to extract secrets for the deploy. Recommended way to set secret key in CI-system.
Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/compose/main.go
Expand Up @@ -131,6 +131,7 @@ func newCmd(ctx context.Context, composeCmdName string, options *newCmdOptions)
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.DisableOptionsInUseLineAnno: "1",
common.DocsLongMD: GetComposeDocs(short).LongMD,
},
Example: options.Example,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/converge/converge.go
Expand Up @@ -74,6 +74,7 @@ werf converge --repo registry.mydomain.com/web --env production`,
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(common.WerfDebugAnsibleArgs, common.WerfSecretKey),
common.DocsLongMD: GetConvergeDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
3 changes: 3 additions & 0 deletions cmd/werf/dismiss/dismiss.go
Expand Up @@ -51,6 +51,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
# Dismiss project using specified helm release name and namespace
$ werf dismiss --release myrelease --namespace myns`,
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.DocsLongMD: GetDismissDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

Expand Down
48 changes: 3 additions & 45 deletions cmd/werf/docs/md_docs.go
Expand Up @@ -3,7 +3,6 @@ package docs
import (
"bytes"
"fmt"
"html"
"io"
"io/ioutil"
"os"
Expand All @@ -13,20 +12,8 @@ import (
"github.com/spf13/cobra"
"mvdan.cc/xurls"

"github.com/werf/werf/cmd/werf/build"
"github.com/werf/werf/cmd/werf/bundle/export"
"github.com/werf/werf/cmd/werf/bundle/publish"
"github.com/werf/werf/cmd/werf/cleanup"
"github.com/werf/werf/cmd/werf/common"
"github.com/werf/werf/cmd/werf/common/templates"
"github.com/werf/werf/cmd/werf/compose"
"github.com/werf/werf/cmd/werf/converge"
"github.com/werf/werf/cmd/werf/dismiss"
export2 "github.com/werf/werf/cmd/werf/export"
"github.com/werf/werf/cmd/werf/kube_run"
"github.com/werf/werf/cmd/werf/purge"
"github.com/werf/werf/cmd/werf/render"
"github.com/werf/werf/cmd/werf/run"
)

func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error {
Expand Down Expand Up @@ -358,38 +345,9 @@ func writeShortCommandMarkdownPartial(cmd *cobra.Command, dir string) error {
}

func getLongFromCommand(cmd *cobra.Command) string {
switch cmd.Short {
case "Build and push images, then deploy application into Kubernetes":
return html.EscapeString(converge.GetConvergeDocs().LongMD)
case "Delete application from Kubernetes":
return html.EscapeString(dismiss.GetDismissDocs().LongMD)
case "Export bundle":
return html.EscapeString(export.GetBundleExportDocs().LongMD)
case "Publish bundle":
return html.EscapeString(publish.GetBundlePublishDocs().LongMD)
case "Cleanup project images in the container registry":
return html.EscapeString(cleanup.GetCleanupDocs().LongMD)
case "Purge all project images in the container registry":
return html.EscapeString(purge.GetPurgeDocs().LongMD)
case "Build images":
return html.EscapeString(build.GetBuildDocs().LongMD)
case "Export images":
return html.EscapeString(export2.GetExportDocs().LongMD)
case "Run container for project image":
return html.EscapeString(run.GetRunDocs().LongMD)
case "Run container for project image in Kubernetes":
return html.EscapeString(kube_run.GetKubeRunDocs().LongMD)
case "Run docker-compose config command with forwarded image names.":
return compose.GetComposeDocs(cmd.Short).LongMD
case "Run docker-compose down command with forwarded image names.":
return compose.GetComposeDocs(cmd.Short).LongMD
case "Run docker-compose run command with forwarded image names.":
return compose.GetComposeDocs(cmd.Short).LongMD
case "Run docker-compose up command with forwarded image names.":
return compose.GetComposeDocs(cmd.Short).LongMD
case "Render Kubernetes templates":
return html.EscapeString(render.GetRenderDocs().LongMD)
default:
if ann, ok := cmd.Annotations[common.DocsLongMD]; ok {
return ann
} else {
if len(cmd.Long) == 0 {
return cmd.Short
} else {
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/export/export.go
Expand Up @@ -42,6 +42,7 @@ func NewExportCmd(ctx context.Context) *cobra.Command {
$ werf export --tag=index.docker.io/company/project:%image%-latest --tag=ghcr.io/company/project/%image%:latest`,
Annotations: map[string]string{
common.DisableOptionsInUseLineAnno: "1",
common.DocsLongMD: GetExportDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/kube_run/kube_run.go
Expand Up @@ -101,6 +101,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
`,
Annotations: map[string]string{
common.DisableOptionsInUseLineAnno: "1",
common.DocsLongMD: GetKubeRunDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletion cmd/werf/kube_run/kube_run_docs.go
Expand Up @@ -7,7 +7,7 @@ func GetKubeRunDocs() structs.DocsStruct {

docs.Long = `Run container in Kubernetes for specified project image from werf.yaml (build if needed).`

docs.LongMD = "Run container in Kubernetes for specified project image from `werf.yaml` (build if needed)"
docs.LongMD = "Run container in Kubernetes for specified project image from `werf.yaml` (build if needed)."

return docs
}
3 changes: 3 additions & 0 deletions cmd/werf/purge/purge.go
Expand Up @@ -28,6 +28,9 @@ func NewCmd(ctx context.Context) *cobra.Command {
DisableFlagsInUseLine: true,
Short: "Purge all project images in the container registry",
Long: common.GetLongCommandDescription(GetPurgeDocs().Long),
Annotations: map[string]string{
common.DocsLongMD: GetPurgeDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

Expand Down
1 change: 1 addition & 0 deletions cmd/werf/render/render.go
Expand Up @@ -56,6 +56,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
DisableFlagsInUseLine: true,
Annotations: map[string]string{
common.CmdEnvAnno: common.EnvsDescription(common.WerfDebugAnsibleArgs, common.WerfSecretKey),
common.DocsLongMD: GetRenderDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
1 change: 1 addition & 0 deletions cmd/werf/run/run.go
Expand Up @@ -67,6 +67,7 @@ func NewCmd(ctx context.Context) *cobra.Command {
docker run -ti --rm image-stage-test:1ffe83860127e68e893b6aece5b0b7619f903f8492a285c6410371c87018c6a0 /bin/sh`,
Annotations: map[string]string{
common.DisableOptionsInUseLineAnno: "1",
common.DocsLongMD: GetRunDocs().LongMD,
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_bundle_render.md
Expand Up @@ -16,7 +16,7 @@ werf bundle render [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_converge.md
Expand Up @@ -30,7 +30,7 @@ werf converge --repo registry.mydomain.com/web --env production
```shell
$WERF_DEBUG_ANSIBLE_ARGS Pass specified cli args to ansible ($ANSIBLE_ARGS)
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended
way to set secret key in CI-system.
way to set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_export.md
Expand Up @@ -8,7 +8,7 @@ Export images to an arbitrary repository according to a template specified by th
The tag may contain the following shortcuts:
- `image`, `image_slug` or `image_safe_slug` to use the image name (necessary if there is more than one image in the werf config);
- `image_content_based_tag` to use a content-based tag.
All meta-information related to werf is removed from the exported images, and then images are completely under the user's responsibility.
All meta-information related to werf is removed from the exported images, and then images are completely under the user's responsibility.

{{ header }} Syntax

Expand Down
Expand Up @@ -17,7 +17,7 @@ werf helm get-autogenerated-values [IMAGE_NAME...] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_helm_secret_decrypt.md
Expand Up @@ -29,7 +29,7 @@ werf helm secret decrypt [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_helm_secret_encrypt.md
Expand Up @@ -28,7 +28,7 @@ werf helm secret encrypt [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -27,7 +27,7 @@ werf helm secret file decrypt [FILE_PATH] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_helm_secret_file_edit.md
Expand Up @@ -23,7 +23,7 @@ werf helm secret file edit FILE_PATH [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -23,7 +23,7 @@ werf helm secret file encrypt [FILE_PATH] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -23,7 +23,7 @@ werf helm secret rotate-secret-key [EXTRA_SECRET_VALUES_FILE_PATH...] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way
to set secret key in CI-system.
to set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -32,7 +32,7 @@ werf helm secret values decrypt [FILE_PATH] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -23,7 +23,7 @@ werf helm secret values edit FILE_PATH [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
Expand Up @@ -23,7 +23,7 @@ werf helm secret values encrypt [FILE_PATH] [options]

```shell
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended way to
set secret key in CI-system.
set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_kube_run.md
Expand Up @@ -3,7 +3,7 @@
{% else %}
{% assign header = "###" %}
{% endif %}
Run container in Kubernetes for specified project image from `werf.yaml` (build if needed)
Run container in Kubernetes for specified project image from `werf.yaml` (build if needed).

{{ header }} Syntax

Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_kubectl_get.md
Expand Up @@ -14,7 +14,7 @@ Use "kubectl api-resources" for a complete list of supported resources.
{{ header }} Syntax

```shell
werf kubectl get [(-o|--output=)json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file|custom-columns|custom-columns-file|wide] (TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags] [options]
werf kubectl get [(-o|--output=)json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file|custom-columns-file|custom-columns|wide] (TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags] [options]
```

{{ header }} Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/reference/cli/werf_render.md
Expand Up @@ -16,7 +16,7 @@ werf render [IMAGE_NAME...] [options]
```shell
$WERF_DEBUG_ANSIBLE_ARGS Pass specified cli args to ansible ($ANSIBLE_ARGS)
$WERF_SECRET_KEY Use specified secret key to extract secrets for the deploy. Recommended
way to set secret key in CI-system.
way to set secret key in CI-system.

Secret key also can be defined in files:
* ~/.werf/global_secret_key (globally),
Expand Down

0 comments on commit 5261f5c

Please sign in to comment.