Skip to content

Commit 2188254

Browse files
committed
feature: add command and sub-commands for security groups
1 parent 0312d28 commit 2188254

File tree

7 files changed

+194
-0
lines changed

7 files changed

+194
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package create
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
8+
)
9+
10+
func NewCmd(p *print.Printer) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "create",
13+
Short: "create security groups",
14+
Long: "create security groups",
15+
Args: args.NoArgs,
16+
Example: examples.Build(
17+
examples.NewExample(`example 1`, `foo bar baz`),
18+
examples.NewExample(`example 2`, `foo bar baz`),
19+
),
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return executeCreate(cmd, p, args)
22+
},
23+
}
24+
cmd.Flags().String("dummy", "foo", "fooify")
25+
return cmd
26+
}
27+
28+
func executeCreate(cmd *cobra.Command, p *print.Printer, args []string) error {
29+
p.Info("executing create command")
30+
return nil
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package delete
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
8+
)
9+
10+
func NewCmd(p *print.Printer) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "delete",
13+
Short: "delete security groups",
14+
Long: "delete security groups",
15+
Args: args.NoArgs,
16+
Example: examples.Build(
17+
examples.NewExample(`example 1`, `foo bar baz`),
18+
examples.NewExample(`example 2`, `foo bar baz`),
19+
),
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return executeDelete(cmd, p, args)
22+
},
23+
}
24+
cmd.Flags().String("dummy", "foo", "fooify")
25+
return cmd
26+
}
27+
28+
func executeDelete(cmd *cobra.Command, p *print.Printer, args []string) error {
29+
p.Info("executing create command")
30+
return nil
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package describe
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
8+
)
9+
10+
func NewCmd(p *print.Printer) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "describe",
13+
Short: "describe security groups",
14+
Long: "describe security groups",
15+
Args: args.NoArgs,
16+
Example: examples.Build(
17+
examples.NewExample(`example 1`, `foo bar baz`),
18+
examples.NewExample(`example 2`, `foo bar baz`),
19+
),
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return executeDescribe(cmd, p, args)
22+
},
23+
}
24+
cmd.Flags().String("dummy", "foo", "fooify")
25+
return cmd
26+
}
27+
28+
func executeDescribe(cmd *cobra.Command, p *print.Printer, args []string) error {
29+
p.Info("executing describe command")
30+
return nil
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package list
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
8+
)
9+
10+
func NewCmd(p *print.Printer) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "list",
13+
Short: "list security groups",
14+
Long: "list security groups",
15+
Args: args.NoArgs,
16+
Example: examples.Build(
17+
examples.NewExample(`example 1`, `foo bar baz`),
18+
examples.NewExample(`example 2`, `foo bar baz`),
19+
),
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return executeList(cmd, p, args)
22+
},
23+
}
24+
cmd.Flags().String("dummy", "foo", "fooify")
25+
return cmd
26+
}
27+
28+
func executeList(cmd *cobra.Command, p *print.Printer, args []string) error {
29+
p.Info("executing list command")
30+
return nil
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package security_group
2+
3+
import (
4+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group/create"
5+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group/delete"
6+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group/describe"
7+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group/list"
8+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group/update"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
11+
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
13+
14+
"github.com/spf13/cobra"
15+
)
16+
17+
func NewCmd(p *print.Printer) *cobra.Command {
18+
cmd := &cobra.Command{
19+
Use: "security-group",
20+
Short: "manage security groups.",
21+
Long: "manage the lifecycle of security groups.",
22+
Args: args.NoArgs,
23+
Run: utils.CmdHelp,
24+
}
25+
addSubcommands(cmd, p)
26+
return cmd
27+
}
28+
29+
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
30+
cmd.AddCommand(
31+
create.NewCmd(p),
32+
delete.NewCmd(p),
33+
describe.NewCmd(p),
34+
list.NewCmd(p),
35+
update.NewCmd(p),
36+
)
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package update
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
8+
)
9+
10+
func NewCmd(p *print.Printer) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "update",
13+
Short: "update security groups",
14+
Long: "update security groups",
15+
Args: args.NoArgs,
16+
Example: examples.Build(
17+
examples.NewExample(`example 1`, `foo bar baz`),
18+
examples.NewExample(`example 2`, `foo bar baz`),
19+
),
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
return executeUpdate(cmd, p, args)
22+
},
23+
}
24+
cmd.Flags().String("dummy", "foo", "fooify")
25+
return cmd
26+
}
27+
28+
func executeUpdate(cmd *cobra.Command, p *print.Printer, args []string) error {
29+
p.Info("executing update command")
30+
return nil
31+
}

internal/cmd/beta/beta.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package beta
33
import (
44
"fmt"
55

6+
"github.com/stackitcloud/stackit-cli/internal/cmd/auth/security_group"
67
keypair "github.com/stackitcloud/stackit-cli/internal/cmd/beta/key-pair"
78
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/network"
89
networkArea "github.com/stackitcloud/stackit-cli/internal/cmd/beta/network-area"
@@ -49,5 +50,6 @@ func addSubcommands(cmd *cobra.Command, p *print.Printer) {
4950
cmd.AddCommand(volume.NewCmd(p))
5051
cmd.AddCommand(networkinterface.NewCmd(p))
5152
cmd.AddCommand(publicip.NewCmd(p))
53+
cmd.AddCommand(security_group.NewCmd(p))
5254
cmd.AddCommand(keypair.NewCmd(p))
5355
}

0 commit comments

Comments
 (0)