Skip to content

Commit

Permalink
Merge pull request #409 from KeerthanaAP/add_group
Browse files Browse the repository at this point in the history
Added groups for commands in help
  • Loading branch information
ppc64le-cloud-bot committed Mar 15, 2023
2 parents 588d2b3 + d5eb389 commit 07595c8
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 21 deletions.
7 changes: 4 additions & 3 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
)

var Cmd = &cobra.Command{
Use: "create",
Short: "Create the resources",
Long: `Create the resources`,
Use: "create",
Short: "Create the resources",
Long: `Create the resources`,
GroupID: "resource",
}

func init() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
)

var Cmd = &cobra.Command{
Use: "delete",
Short: "Delete the resources",
Long: `Delete the resources`,
Use: "delete",
Short: "Delete the resources",
Long: `Delete the resources`,
GroupID: "resource",
}

func init() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/dhcp-sync/dhcp-sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ func syncDHCPD() {
}

var Cmd = &cobra.Command{
Use: "dhcp-sync",
Short: "dhcp-sync command",
Long: `dhcp-sync tool is a tool populating the dhcpd.conf file from the PowerVS network and restart the dhcpd service.`,
Use: "dhcp-sync",
Short: "dhcp-sync command",
Long: `dhcp-sync tool is a tool populating the dhcpd.conf file from the PowerVS network and restart the dhcpd service.`,
GroupID: "dhcp",
PreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.Options.InstanceID == "" {
return fmt.Errorf("--instance-id is required")
Expand Down
5 changes: 3 additions & 2 deletions cmd/dhcpserver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
)

var Cmd = &cobra.Command{
Use: "dhcpserver",
Short: "dhcpserver command",
Use: "dhcpserver",
Short: "dhcpserver command",
GroupID: "dhcp",
PreRunE: func(cmd *cobra.Command, args []string) error {
if pkg.Options.APIKey == "" {
return fmt.Errorf("api-key can't be empty, pass the token via --api-key or set IBMCLOUD_API_KEY environment variable")
Expand Down
7 changes: 4 additions & 3 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
)

var Cmd = &cobra.Command{
Use: "get",
Short: "Get the resources",
Long: `Get the resources`,
Use: "get",
Short: "Get the resources",
Long: `Get the resources`,
GroupID: "resource",
}

func init() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

var Cmd = &cobra.Command{
Use: "image",
Short: "PowerVS Image management",
Long: `PowerVS Image management`,
Use: "image",
Short: "PowerVS Image management",
Long: `PowerVS Image management`,
GroupID: "image",
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions cmd/purge/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package images

import (
"fmt"

"github.com/ppc64le-cloud/pvsadm/pkg"
"github.com/ppc64le-cloud/pvsadm/pkg/audit"
"github.com/ppc64le-cloud/pvsadm/pkg/client"
Expand Down
1 change: 1 addition & 0 deletions cmd/purge/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Examples:
# Delete all the ssh keys starts with rdr-
pvsadm purge keys --instance-name upstream-core --regexp "^rdr-.*"
`,
GroupID: "resource",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Code block to execute the strict check mentioned in the rootcmd for the environment.
// This block is needed as a workaround mentioned in https://github.com/spf13/cobra/issues/252
Expand Down
3 changes: 2 additions & 1 deletion cmd/purge/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ package volumes

import (
"fmt"
"time"

"github.com/ppc64le-cloud/pvsadm/pkg"
"github.com/ppc64le-cloud/pvsadm/pkg/audit"
"github.com/ppc64le-cloud/pvsadm/pkg/client"
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
"time"
)

var before time.Duration
Expand Down
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func init() {
klog.InitFlags(nil)
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)

rootCmd.AddGroup(&cobra.Group{ID: "resource", Title: "Resource Management Commands:"})
rootCmd.AddGroup(&cobra.Group{ID: "dhcp", Title: "DHCP Commands:"})
rootCmd.AddGroup(&cobra.Group{ID: "image", Title: "Image Commands:"})
rootCmd.AddGroup(&cobra.Group{ID: "admin", Title: "Administration Commands:"})
rootCmd.SetHelpCommandGroupID("admin")
rootCmd.SetCompletionCommandGroupID("admin")
rootCmd.AddCommand(purge.Cmd)
rootCmd.AddCommand(get.Cmd)
rootCmd.AddCommand(version.Cmd)
Expand Down
8 changes: 5 additions & 3 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ package version

import (
"fmt"
"github.com/ppc64le-cloud/pvsadm/pkg/version"
"runtime"

"github.com/ppc64le-cloud/pvsadm/pkg/version"

"github.com/spf13/cobra"
)

var Cmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Use: "version",
Short: "Print the version number",
GroupID: "admin",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s, GoVersion: %s\n", version.Get(), runtime.Version())
},
Expand Down

0 comments on commit 07595c8

Please sign in to comment.