Skip to content

Commit 3c70a19

Browse files
atulpatel261194glimchb
authored andcommitted
fix(issue160): hierarchical command structure
Signed-off-by: atulpatel261194 <[email protected]>
1 parent c3d720f commit 3c70a19

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

cmd/inventory-get.go

+20
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ func NewGetCommand() *cobra.Command {
4343
flags.StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")
4444
return cmd
4545
}
46+
47+
// NewInventoryCommand tests the inventory
48+
func NewInventoryCommand() *cobra.Command {
49+
cmd := &cobra.Command{
50+
Use: "inventory",
51+
Aliases: []string{"g"},
52+
Short: "Tests inventory functionality",
53+
Args: cobra.NoArgs,
54+
Run: func(cmd *cobra.Command, args []string) {
55+
err := cmd.Help()
56+
if err != nil {
57+
log.Fatalf("[ERROR] %s", err.Error())
58+
}
59+
},
60+
}
61+
62+
cmd.AddCommand(NewGetCommand())
63+
64+
return cmd
65+
}

cmd/ipsec-stats.go

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66

77
import (
88
"fmt"
9+
"log"
910

1011
"github.com/opiproject/godpu/ipsec"
1112
"github.com/spf13/cobra"
@@ -30,3 +31,23 @@ func NewStatsCommand() *cobra.Command {
3031
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
3132
return cmd
3233
}
34+
35+
// NewIPSecCommand tests the inventory
36+
func NewIPSecCommand() *cobra.Command {
37+
cmd := &cobra.Command{
38+
Use: "ipsec",
39+
Aliases: []string{"g"},
40+
Short: "Tests ipsec functionality",
41+
Args: cobra.NoArgs,
42+
Run: func(cmd *cobra.Command, args []string) {
43+
err := cmd.Help()
44+
if err != nil {
45+
log.Fatalf("[ERROR] %s", err.Error())
46+
}
47+
},
48+
}
49+
50+
cmd.AddCommand(NewStatsCommand())
51+
cmd.AddCommand(NewTestCommand())
52+
return cmd
53+
}

cmd/storage-test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewStorageTestCommand() *cobra.Command {
2222
addr string
2323
)
2424
cmd := &cobra.Command{
25-
Use: "storagetest",
25+
Use: "test",
2626
Aliases: []string{"s"},
2727
Short: "Test storage functionality",
2828
Args: cobra.NoArgs,
@@ -72,3 +72,22 @@ func NewStorageTestCommand() *cobra.Command {
7272
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
7373
return cmd
7474
}
75+
76+
// NewStorageCommand tests the storage functionality
77+
func NewStorageCommand() *cobra.Command {
78+
cmd := &cobra.Command{
79+
Use: "storage",
80+
Aliases: []string{"g"},
81+
Short: "Tests storage functionality",
82+
Args: cobra.NoArgs,
83+
Run: func(cmd *cobra.Command, args []string) {
84+
err := cmd.Help()
85+
if err != nil {
86+
log.Fatalf("[ERROR] %s", err.Error())
87+
}
88+
},
89+
}
90+
91+
cmd.AddCommand(NewStorageTestCommand())
92+
return cmd
93+
}

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ services:
7373
depends_on:
7474
opi-smbios-server:
7575
condition: service_healthy
76-
command: get --addr opi-smbios-server:50051
76+
command: inventory get --addr opi-smbios-server:50051
7777

7878
opi-test:
7979
build:
@@ -83,7 +83,7 @@ services:
8383
depends_on:
8484
opi-spdk-server:
8585
condition: service_healthy
86-
command: storagetest --addr opi-spdk-server:50051
86+
command: storage test --addr opi-spdk-server:50051
8787

8888
networks:
8989
opi:

main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ func newCommand() *cobra.Command {
3535
os.Exit(1)
3636
},
3737
}
38-
c.AddCommand(cmd.NewGetCommand())
39-
c.AddCommand(cmd.NewTestCommand())
40-
c.AddCommand(cmd.NewStatsCommand())
41-
c.AddCommand(cmd.NewStorageTestCommand())
38+
c.AddCommand(cmd.NewInventoryCommand())
39+
c.AddCommand(cmd.NewIPSecCommand())
40+
c.AddCommand(cmd.NewStorageCommand())
4241
c.AddCommand(cmd.NewEvpnCommand())
4342
return c
4443
}

0 commit comments

Comments
 (0)