Skip to content

Commit

Permalink
Example of how to do bash in our CLI help
Browse files Browse the repository at this point in the history
* Use the pretty.LongDesc function (which doesn't pipe it through
markdown -> ascii)
* Use pretty.Bash helper to avoid problems with backticks in
go-backtick-quoted-strings
* Make sure indentation is consistent
  • Loading branch information
justinsb committed Jul 15, 2017
1 parent d2e5ec2 commit f2eccbb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
21 changes: 11 additions & 10 deletions cmd/kops/edit_federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,35 @@ package main
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"

"io"

"github.com/spf13/cobra"
"k8s.io/kops/cmd/kops/util"
kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/kops/validation"
"k8s.io/kops/pkg/pretty"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/editor"
"k8s.io/kubernetes/pkg/util/i18n"
)

var (
edit_federation_long = templates.LongDesc(i18n.T(`Edit a cluster configuration.
edit_federation_long = pretty.LongDesc(`
Edit a cluster configuration.
This command changes the federation cloud specification in the registry.
This command changes the federation cloud specification in the registry.
To set your preferred editor, you can define the EDITOR environment variable.
When you have done this, kops will use the editor that you have set.
To set your preferred editor, you can define the EDITOR environment variable.
When you have done this, kops will use the editor that you have set.
kops edit does not update the cloud resources, to apply the changes use "kops update cluster".`))
kops edit does not update the cloud resources, to apply the changes use ` + pretty.Bash("kops update cluster") + `.`)

edit_federation_example = templates.Examples(i18n.T(`
# Edit a cluster dederation configuration.
kops edit federation k8s-cluster.example.com --state=s3://kops-state-1234
`))
# Edit a cluster dederation configuration.
kops edit federation k8s-cluster.example.com --state=s3://kops-state-1234
`))

edit_federation_short = i18n.T(`Edit federation.`)
)
Expand Down
12 changes: 6 additions & 6 deletions docs/cli/kops_edit_federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Edit federation.
### Synopsis


Edit a cluster configuration.
Edit a cluster configuration.

This command changes the federation cloud specification in the registry.
This command changes the federation cloud specification in the registry.

To set your preferred editor, you can define the EDITOR environment variable.
When you have done this, kops will use the editor that you have set.
kops edit does not update the cloud resources, to apply the changes use "kops update cluster".
To set your preferred editor, you can define the EDITOR environment variable.
When you have done this, kops will use the editor that you have set.

kops edit does not update the cloud resources, to apply the changes use `kops update cluster`.

```
kops edit federation
Expand Down
17 changes: 17 additions & 0 deletions pkg/pretty/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pretty

import (
"fmt"
"github.com/MakeNowJust/heredoc"
"strings"
)

func Bash(s string) string {
return fmt.Sprintf("`%s`", s)
}

func LongDesc(s string) string {
s = heredoc.Doc(s)
s = strings.TrimSpace(s)
return s
}

0 comments on commit f2eccbb

Please sign in to comment.