Skip to content

Commit

Permalink
help text - cmd names externalized (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Dec 10, 2018
1 parent e3a4f0d commit f834e51
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/add.go
Expand Up @@ -22,7 +22,7 @@ import (
// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add",
Short: "Add assets such as accounts, imports, users, clusters, servers",
Short: "Add assets such as accounts, imports, users",
}

func init() {
Expand Down
3 changes: 2 additions & 1 deletion cmd/addcluster.go
Expand Up @@ -28,9 +28,10 @@ func createAddClusterCmd() *cobra.Command {
var params AddClusterParams
cmd := &cobra.Command{
Use: "cluster",
Hidden: true,
Short: "Add a cluster (operator only)",
Args: MaxArgs(0),
Example: `nsc add cluster --name mycluster --trusted-accounts actkey1,actkey2 --trusted-operators opkey1,opkey2`,
Example: fmt.Sprintf(`%s add cluster --name mycluster --trusted-accounts actkey1,actkey2 --trusted-operators opkey1,opkey2`, GetToolName()),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
Expand Down
20 changes: 13 additions & 7 deletions cmd/addexport.go
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"errors"
"fmt"
"strings"

"github.com/nats-io/jwt"
"github.com/nats-io/nkeys"
Expand All @@ -28,13 +29,10 @@ import (
func createAddExportCmd() *cobra.Command {
var params AddExportParams
cmd := &cobra.Command{
Use: "export",
Short: "Add an export",
Args: MaxArgs(0),
Example: `nsc add export -i
nsc add export --subject "a.b.c.>"
nsc add export --service --subject a.b
ncc add export --name myexport --subject a.b --service`,
Use: "export",
Short: "Add an export",
Args: MaxArgs(0),
Example: params.longHelp(),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
Expand Down Expand Up @@ -74,6 +72,14 @@ type AddExportParams struct {
subject string
}

func (p *AddExportParams) longHelp() string {
s := `toolName add export -i
toolName add export --subject "a.b.c.>"
toolName add export --service --subject a.b
toolName add export --name myexport --subject a.b --service`
return strings.Replace(s, "toolName", GetToolName(), -1)
}

func (p *AddExportParams) SetDefaults(ctx ActionCtx) error {
p.AccountContextParams.SetDefaults(ctx)

Expand Down
3 changes: 2 additions & 1 deletion cmd/addserver.go
Expand Up @@ -32,7 +32,8 @@ func createAddServerCmd() *cobra.Command {
Short: "Add a server to a cluster (operator only)",
Args: MaxArgs(0),
SilenceUsage: true,
Example: `nsc add server -i`,
Hidden: true,
Example: fmt.Sprintf(`%s add server -i`, GetToolName()),
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down
13 changes: 10 additions & 3 deletions cmd/adduser.go
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"sort"
"strings"

"github.com/nats-io/jwt"
"github.com/nats-io/nkeys"
Expand All @@ -32,9 +33,7 @@ func CreateAddUserCmd() *cobra.Command {
Short: "Add an user to the account",
Args: MaxArgs(0),
SilenceUsage: true,
Example: `nsc add user -i
nsc add user --name u --deny-pubsub "bar.>"
nsc add user --name u --tag test,service_a`,
Example: params.longHelp(),
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down Expand Up @@ -94,6 +93,14 @@ type AddUserParams struct {
tags []string
}

func (p *AddUserParams) longHelp() string {
s := `toolName add user -i
toolName add user --name u --deny-pubsub "bar.>"
toolName add user --name u --tag test,service_a`

return strings.Replace(s, "toolName", GetToolName(), -1)
}

func (p *AddUserParams) SetDefaults(ctx ActionCtx) error {
p.AccountContextParams.SetDefaults(ctx)

Expand Down
16 changes: 11 additions & 5 deletions cmd/deleteimport.go
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/nats-io/jwt"
"github.com/nats-io/nkeys"
Expand All @@ -27,11 +28,10 @@ import (
func createDeleteImportCmd() *cobra.Command {
var params DeleteImportParams
cmd := &cobra.Command{
Use: "import",
Short: "Delete an import",
Args: MaxArgs(0),
Example: `nsc delete import -i
nsc delete import -s "bar.>"`,
Use: "import",
Short: "Delete an import",
Args: MaxArgs(0),
Example: params.longHelp(),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
Expand Down Expand Up @@ -62,6 +62,12 @@ type DeleteImportParams struct {
service bool
}

func (p *DeleteImportParams) longHelp() string {
v := `toolName delete import -i
toolName delete import -s "bar.>"`
return strings.Replace(v, "toolName", GetToolName(), -1)
}

func (p *DeleteImportParams) SetDefaults(ctx ActionCtx) error {
if err := p.AccountContextParams.SetDefaults(ctx); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/describe.go
Expand Up @@ -21,7 +21,7 @@ import (

var describeCmd = &cobra.Command{
Use: "describe",
Short: "Describe assets such as operators, accounts, users, clusters, servers and jwt files",
Short: "Describe assets such as operators, accounts, users, and jwt files",
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions cmd/describecluster.go
Expand Up @@ -30,6 +30,7 @@ func createDescribeClusterCmd() *cobra.Command {
Short: "Describes a cluster",
Args: MaxArgs(0),
SilenceUsage: true,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/describejwt.go
Expand Up @@ -31,7 +31,7 @@ func createDescribeJwtCmd() *cobra.Command {
Use: "jwt",
Short: "Describe a jwt file",
Args: MaxArgs(0),
Example: `nsc describe -f pathorurl`,
Example: fmt.Sprintf(`%s describe -f pathorurl`, GetToolName()),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunStoreLessAction(cmd, args, &params); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/describeserver.go
Expand Up @@ -30,6 +30,7 @@ func createDescribeServerCmd() *cobra.Command {
Short: "Describes a server",
Args: MaxArgs(0),
SilenceUsage: true,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/editcluster.go
Expand Up @@ -31,6 +31,7 @@ func createEditClusterCmd() *cobra.Command {
Short: "Edit a cluster",
Args: MaxArgs(0),
SilenceUsage: true,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/editserver.go
Expand Up @@ -32,6 +32,7 @@ func createEditServerCmd() *cobra.Command {
Short: "Edit a server",
Args: MaxArgs(0),
SilenceUsage: true,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunAction(cmd, args, &params); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/generate.go
Expand Up @@ -22,7 +22,7 @@ import (
// addCmd represents the add command
var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate an activation token",
Short: "Generate activation tokens or configs",
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions cmd/generateoperatorconfig.go
Expand Up @@ -31,6 +31,7 @@ func createGenerateOperatorConfigCmd() *cobra.Command {
Short: "Generate an operator config",
Args: MaxArgs(0),
SilenceUsage: true,
Hidden: true,
Example: `nsc generate operator --n a`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := RunMaybeStorelessAction(cmd, args, &params); err != nil {
Expand Down
17 changes: 11 additions & 6 deletions cmd/update.go
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"
"os"
"strings"
"time"

"github.com/blang/semver"
Expand All @@ -27,15 +28,19 @@ import (
"github.com/spf13/cobra"
)

func updateHelp() string {
v := `toolName update
toolName update --release-notes`
return strings.Replace(v, "toolName", GetToolName(), -1)
}

func createUpdateCommand() *cobra.Command {
var printReleaseNotes bool
var cmd = &cobra.Command{
Example: `update
update --release-notes
`,
Use: "update",
Short: "Update this tool to latest version",
Args: MaxArgs(0),
Example: updateHelp(),
Use: "update",
Short: "Update this tool to latest version",
Args: MaxArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
v := semver.MustParse(GetRootCmd().Version)

Expand Down

0 comments on commit f834e51

Please sign in to comment.