Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 6 additions & 5 deletions internal/cmd/argus/argus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance"
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/plans"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "argus",
Short: "Provides functionality for Argus",
Long: "Provides functionality for Argus.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd)
addSubcommands(cmd, p)
return cmd
}

func addSubcommands(cmd *cobra.Command) {
cmd.AddCommand(plans.NewCmd())
cmd.AddCommand(instance.NewCmd())
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(plans.NewCmd(p))
cmd.AddCommand(instance.NewCmd(p))
}
5 changes: 3 additions & 2 deletions internal/cmd/argus/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils"
Expand All @@ -35,7 +36,7 @@ type inputModel struct {
PlanId *string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Creates an Argus instance",
Expand Down Expand Up @@ -105,7 +106,7 @@ func NewCmd() *cobra.Command {
if model.Async {
operationState = "Triggered creation of"
}
cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId)
p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/argus/instance/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/argus/instance/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
Expand All @@ -28,7 +29,7 @@ type inputModel struct {
InstanceId string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("delete %s", instanceIdArg),
Short: "Deletes an Argus instance",
Expand Down Expand Up @@ -87,7 +88,7 @@ func NewCmd() *cobra.Command {
if model.Async {
operationState = "Triggered deletion of"
}
cmd.Printf("%s instance %q\n", operationState, instanceLabel)
p.Info("%s instance %q\n", operationState, instanceLabel)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/argus/instance/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/argus/instance/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
Expand All @@ -26,7 +27,7 @@ type inputModel struct {
InstanceId string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", instanceIdArg),
Short: "Shows details of an Argus instance",
Expand Down Expand Up @@ -59,7 +60,7 @@ func NewCmd() *cobra.Command {
return fmt.Errorf("read Argus instance: %w", err)
}

return outputResult(cmd, model.OutputFormat, resp)
return outputResult(cmd, model.OutputFormat, resp, p)
},
}
return cmd
Expand All @@ -84,7 +85,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl
return req
}

func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetInstanceResponse) error {
func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetInstanceResponse, p *print.Printer) error {
switch outputFormat {
case globalflags.PrettyOutputFormat:

Expand Down Expand Up @@ -120,7 +121,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetIn
if err != nil {
return fmt.Errorf("marshal Argus instance: %w", err)
}
cmd.Println(string(details))
p.Outputln(string(details))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/argus/instance/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/argus/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import (
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance/list"
"github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance/update"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "instance",
Short: "Provides functionality for Argus instances",
Long: "Provides functionality for Argus instances.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd)
addSubcommands(cmd, p)
return cmd
}

func addSubcommands(cmd *cobra.Command) {
cmd.AddCommand(create.NewCmd())
cmd.AddCommand(update.NewCmd())
cmd.AddCommand(delete.NewCmd())
cmd.AddCommand(list.NewCmd())
cmd.AddCommand(describe.NewCmd())
func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(create.NewCmd(p))
cmd.AddCommand(update.NewCmd(p))
cmd.AddCommand(delete.NewCmd(p))
cmd.AddCommand(list.NewCmd(p))
cmd.AddCommand(describe.NewCmd(p))
}
11 changes: 6 additions & 5 deletions internal/cmd/argus/instance/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
Expand All @@ -27,7 +28,7 @@ type inputModel struct {
Limit *int64
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Lists all Argus instances",
Expand Down Expand Up @@ -69,7 +70,7 @@ func NewCmd() *cobra.Command {
if err != nil {
projectLabel = model.ProjectId
}
cmd.Printf("No instances found for project %q\n", projectLabel)
p.Info("No instances found for project %q\n", projectLabel)
return nil
}

Expand All @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command {
instances = instances[:*model.Limit]
}

return outputResult(cmd, model.OutputFormat, instances)
return outputResult(cmd, model.OutputFormat, instances, p)
},
}

Expand Down Expand Up @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl
return req
}

func outputResult(cmd *cobra.Command, outputFormat string, instances []argus.ProjectInstanceFull) error {
func outputResult(cmd *cobra.Command, outputFormat string, instances []argus.ProjectInstanceFull, p *print.Printer) error {
switch outputFormat {
case globalflags.JSONOutputFormat:
details, err := json.MarshalIndent(instances, "", " ")
if err != nil {
return fmt.Errorf("marshal Argus instance list: %w", err)
}
cmd.Println(string(details))
p.Outputln(string(details))

return nil
default:
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/argus/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils"
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
Expand Down Expand Up @@ -38,7 +39,7 @@ type inputModel struct {
PlanId *string
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("update %s", instanceIdArg),
Short: "Updates an Argus instance",
Expand Down Expand Up @@ -112,7 +113,7 @@ func NewCmd() *cobra.Command {
if model.Async {
operationState = "Triggered update of"
}
cmd.Printf("%s instance %q\n", operationState, instanceLabel)
p.Info("%s instance %q\n", operationState, instanceLabel)
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/argus/instance/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestParseInput(t *testing.T) {

for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
cmd := NewCmd()
cmd := NewCmd(nil)
err := globalflags.Configure(cmd.Flags())
if err != nil {
t.Fatalf("configure global flags: %v", err)
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/argus/plans/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
Expand All @@ -27,7 +28,7 @@ type inputModel struct {
Limit *int64
}

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "plans",
Short: "Lists all Argus service plans",
Expand Down Expand Up @@ -69,7 +70,7 @@ func NewCmd() *cobra.Command {
if err != nil {
projectLabel = model.ProjectId
}
cmd.Printf("No plans found for project %q\n", projectLabel)
p.Info("No plans found for project %q\n", projectLabel)
return nil
}

Expand All @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command {
plans = plans[:*model.Limit]
}

return outputResult(cmd, model.OutputFormat, plans)
return outputResult(cmd, model.OutputFormat, plans, p)
},
}

Expand Down Expand Up @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl
return req
}

func outputResult(cmd *cobra.Command, outputFormat string, plans []argus.Plan) error {
func outputResult(cmd *cobra.Command, outputFormat string, plans []argus.Plan, p *print.Printer) error {
switch outputFormat {
case globalflags.JSONOutputFormat:
details, err := json.MarshalIndent(plans, "", " ")
if err != nil {
return fmt.Errorf("marshal Argus plans: %w", err)
}
cmd.Println(string(details))
p.Outputln(string(details))

return nil
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func NewCmd(p *print.Printer) *cobra.Command {
}

func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(login.NewCmd())
cmd.AddCommand(login.NewCmd(p))
cmd.AddCommand(activateserviceaccount.NewCmd(p))
}
5 changes: 3 additions & 2 deletions internal/cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "Logs in to the STACKIT CLI",
Expand All @@ -27,7 +28,7 @@ func NewCmd() *cobra.Command {
return fmt.Errorf("authorization failed: %w", err)
}

cmd.Println("Successfully logged into STACKIT CLI.")
p.Info("Successfully logged into STACKIT CLI.\n")
Comment thread
DiogoFerrao marked this conversation as resolved.
return nil
},
}
Expand Down
Loading