diff --git a/docs/stackit_mongodbflex_backup.md b/docs/stackit_mongodbflex_backup.md index 19e304c76..de46caf3a 100644 --- a/docs/stackit_mongodbflex_backup.md +++ b/docs/stackit_mongodbflex_backup.md @@ -21,7 +21,7 @@ stackit mongodbflex backup [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_describe.md b/docs/stackit_mongodbflex_backup_describe.md index ca87bee8e..bb422f064 100644 --- a/docs/stackit_mongodbflex_backup_describe.md +++ b/docs/stackit_mongodbflex_backup_describe.md @@ -32,7 +32,7 @@ stackit mongodbflex backup describe BACKUP_ID [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_list.md b/docs/stackit_mongodbflex_backup_list.md index a8a0617e3..611ae3a22 100644 --- a/docs/stackit_mongodbflex_backup_list.md +++ b/docs/stackit_mongodbflex_backup_list.md @@ -36,7 +36,7 @@ stackit mongodbflex backup list [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_restore-jobs.md b/docs/stackit_mongodbflex_backup_restore-jobs.md index af5626306..8b909182b 100644 --- a/docs/stackit_mongodbflex_backup_restore-jobs.md +++ b/docs/stackit_mongodbflex_backup_restore-jobs.md @@ -36,7 +36,7 @@ stackit mongodbflex backup restore-jobs [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_restore.md b/docs/stackit_mongodbflex_backup_restore.md index f0f8e00e8..87185a3e2 100644 --- a/docs/stackit_mongodbflex_backup_restore.md +++ b/docs/stackit_mongodbflex_backup_restore.md @@ -40,7 +40,7 @@ stackit mongodbflex backup restore [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_schedule.md b/docs/stackit_mongodbflex_backup_schedule.md index 8993c63c4..945d5081b 100644 --- a/docs/stackit_mongodbflex_backup_schedule.md +++ b/docs/stackit_mongodbflex_backup_schedule.md @@ -32,7 +32,7 @@ stackit mongodbflex backup schedule [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/docs/stackit_mongodbflex_backup_update-schedule.md b/docs/stackit_mongodbflex_backup_update-schedule.md index 38e1e69dc..ee51091cf 100644 --- a/docs/stackit_mongodbflex_backup_update-schedule.md +++ b/docs/stackit_mongodbflex_backup_update-schedule.md @@ -40,7 +40,7 @@ stackit mongodbflex backup update-schedule [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty" "none"] + -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] -p, --project-id string Project ID --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` diff --git a/internal/cmd/mongodbflex/backup/describe/describe.go b/internal/cmd/mongodbflex/backup/describe/describe.go index 94867e5e7..7baa58b2a 100644 --- a/internal/cmd/mongodbflex/backup/describe/describe.go +++ b/internal/cmd/mongodbflex/backup/describe/describe.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "github.com/goccy/go-yaml" "github.com/inhies/go-bytesize" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" @@ -129,10 +130,18 @@ func outputResult(p *print.Printer, cmd *cobra.Command, outputFormat, restoreSta case print.JSONOutputFormat: details, err := json.MarshalIndent(backup, "", " ") if err != nil { - return fmt.Errorf("marshal backup for MongoDB Flex backup: %w", err) + return fmt.Errorf("marshal MongoDB Flex backup: %w", err) } cmd.Println(string(details)) + return nil + case print.YAMLOutputFormat: + details, err := yaml.Marshal(backup) + if err != nil { + return fmt.Errorf("marshal MongoDB Flex backup: %w", err) + } + p.Outputln(string(details)) + return nil default: table := tables.NewTable() diff --git a/internal/cmd/mongodbflex/backup/list/list.go b/internal/cmd/mongodbflex/backup/list/list.go index 694c54769..7dcba1bf2 100644 --- a/internal/cmd/mongodbflex/backup/list/list.go +++ b/internal/cmd/mongodbflex/backup/list/list.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "github.com/goccy/go-yaml" "github.com/inhies/go-bytesize" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -152,6 +153,14 @@ func outputResult(p *print.Printer, outputFormat string, backups []mongodbflex.B } p.Outputln(string(details)) + return nil + case print.YAMLOutputFormat: + details, err := yaml.Marshal(backups) + if err != nil { + return fmt.Errorf("marshal MongoDB Flex backups list: %w", err) + } + p.Outputln(string(details)) + return nil default: table := tables.NewTable() diff --git a/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go b/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go index 537727bd0..c9601df96 100644 --- a/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go +++ b/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -146,6 +147,14 @@ func outputResult(p *print.Printer, outputFormat string, restoreJobs []mongodbfl } p.Outputln(string(details)) + return nil + case print.YAMLOutputFormat: + details, err := yaml.Marshal(restoreJobs) + if err != nil { + return fmt.Errorf("marshal MongoDB Flex restore jobs list: %w", err) + } + p.Outputln(string(details)) + return nil default: table := tables.NewTable() diff --git a/internal/cmd/mongodbflex/backup/schedule/schedule.go b/internal/cmd/mongodbflex/backup/schedule/schedule.go index 3be9badf2..58e120c81 100644 --- a/internal/cmd/mongodbflex/backup/schedule/schedule.go +++ b/internal/cmd/mongodbflex/backup/schedule/schedule.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -103,29 +104,38 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex } func outputResult(p *print.Printer, outputFormat string, instance *mongodbflex.Instance) error { + output := struct { + BackupSchedule string `json:"backup_schedule"` + DailySnaphotRetentionDays string `json:"daily_snapshot_retention_days"` + MonthlySnapshotRetentionMonths string `json:"monthly_snapshot_retention_months"` + PointInTimeWindowHours string `json:"point_in_time_window_hours"` + SnapshotRetentionDays string `json:"snapshot_retention_days"` + WeeklySnapshotRetentionWeeks string `json:"weekly_snapshot_retention_weeks"` + }{ + BackupSchedule: *instance.BackupSchedule, + DailySnaphotRetentionDays: (*instance.Options)["dailySnapshotRetentionDays"], + MonthlySnapshotRetentionMonths: (*instance.Options)["monthlySnapshotRetentionDays"], + PointInTimeWindowHours: (*instance.Options)["pointInTimeWindowHours"], + SnapshotRetentionDays: (*instance.Options)["snapshotRetentionDays"], + WeeklySnapshotRetentionWeeks: (*instance.Options)["weeklySnapshotRetentionWeeks"], + } + switch outputFormat { case print.JSONOutputFormat: - output := struct { - BackupSchedule string `json:"backup_schedule"` - DailySnaphotRetentionDays string `json:"daily_snapshot_retention_days"` - MonthlySnapshotRetentionMonths string `json:"monthly_snapshot_retention_months"` - PointInTimeWindowHours string `json:"point_in_time_window_hours"` - SnapshotRetentionDays string `json:"snapshot_retention_days"` - WeeklySnapshotRetentionWeeks string `json:"weekly_snapshot_retention_weeks"` - }{ - BackupSchedule: *instance.BackupSchedule, - DailySnaphotRetentionDays: (*instance.Options)["dailySnapshotRetentionDays"], - MonthlySnapshotRetentionMonths: (*instance.Options)["monthlySnapshotRetentionDays"], - PointInTimeWindowHours: (*instance.Options)["pointInTimeWindowHours"], - SnapshotRetentionDays: (*instance.Options)["snapshotRetentionDays"], - WeeklySnapshotRetentionWeeks: (*instance.Options)["weeklySnapshotRetentionWeeks"], - } details, err := json.MarshalIndent(output, "", " ") if err != nil { return fmt.Errorf("marshal MongoDB Flex backup schedule: %w", err) } p.Outputln(string(details)) + return nil + case print.YAMLOutputFormat: + details, err := yaml.Marshal(output) + if err != nil { + return fmt.Errorf("marshal MongoDB Flex backup schedule: %w", err) + } + p.Outputln(string(details)) + return nil default: table := tables.NewTable()