Skip to content

Commit

Permalink
fix(issue160): hierarchical command structure
Browse files Browse the repository at this point in the history
Signed-off-by: atulpatel261194 <[email protected]>
  • Loading branch information
atulpatel261194 committed Aug 9, 2023
1 parent c3d720f commit d578ac8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
20 changes: 20 additions & 0 deletions cmd/inventory-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ func NewGetCommand() *cobra.Command {
flags.StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")
return cmd
}

// NewInventoryCommand tests the inventory
func NewInventoryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "inventory",
Aliases: []string{"g"},
Short: "Tests inventory functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}

cmd.AddCommand(NewGetCommand())

return cmd
}
21 changes: 21 additions & 0 deletions cmd/ipsec-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd

import (
"fmt"
"log"

"github.com/opiproject/godpu/ipsec"
"github.com/spf13/cobra"
Expand All @@ -30,3 +31,23 @@ func NewStatsCommand() *cobra.Command {
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
return cmd
}

// NewIPSecCommand tests the inventory
func NewIPSecCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "ipsec",
Aliases: []string{"g"},
Short: "Tests ipsec functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}

cmd.AddCommand(NewStatsCommand())
cmd.AddCommand(NewTestCommand())
return cmd
}
21 changes: 20 additions & 1 deletion cmd/storage-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewStorageTestCommand() *cobra.Command {
addr string
)
cmd := &cobra.Command{
Use: "storagetest",
Use: "test",
Aliases: []string{"s"},
Short: "Test storage functionality",
Args: cobra.NoArgs,
Expand Down Expand Up @@ -72,3 +72,22 @@ func NewStorageTestCommand() *cobra.Command {
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
return cmd
}

// NewStorageCommand tests the storage functionality
func NewStorageCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "storage",
Aliases: []string{"g"},
Short: "Tests storage functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}

cmd.AddCommand(NewStorageTestCommand())
return cmd
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ services:
depends_on:
opi-smbios-server:
condition: service_healthy
command: get --addr opi-smbios-server:50051
command: inventory get --addr opi-smbios-server:50051

opi-test:
build:
Expand All @@ -83,7 +83,7 @@ services:
depends_on:
opi-spdk-server:
condition: service_healthy
command: storagetest --addr opi-spdk-server:50051
command: storage test --addr opi-spdk-server:50051

networks:
opi:
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ func newCommand() *cobra.Command {
os.Exit(1)
},
}
c.AddCommand(cmd.NewGetCommand())
c.AddCommand(cmd.NewTestCommand())
c.AddCommand(cmd.NewStatsCommand())
c.AddCommand(cmd.NewStorageTestCommand())
c.AddCommand(cmd.NewInventoryCommand())
c.AddCommand(cmd.NewIPSecCommand())
c.AddCommand(cmd.NewStorageCommand())
c.AddCommand(cmd.NewEvpnCommand())
return c
}

0 comments on commit d578ac8

Please sign in to comment.