Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of how to do bash in our CLI help #2943

Merged
merged 2 commits into from
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,14 +8,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
1 change: 1 addition & 0 deletions hack/.packages
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ k8s.io/kops/pkg/model/gcemodel
k8s.io/kops/pkg/model/iam
k8s.io/kops/pkg/model/resources
k8s.io/kops/pkg/model/vspheremodel
k8s.io/kops/pkg/pretty
k8s.io/kops/pkg/resources
k8s.io/kops/pkg/resources/digitalocean
k8s.io/kops/pkg/resources/digitalocean/dns
Expand Down
36 changes: 36 additions & 0 deletions pkg/pretty/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pretty

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

// Bash markdown-quotes a bash command for insertion into help text.
func Bash(s string) string {
return fmt.Sprintf("`%s`", s)
}

// LongDesc is used for formatting help text for a commands Long Description.
// It de-dents it and trims it.
func LongDesc(s string) string {
s = heredoc.Doc(s)
s = strings.TrimSpace(s)
return s
}