Skip to content

Commit 41915da

Browse files
GokceGKjoaopalet
andauthored
Add yaml output format to mongodbflex backup commands (#319)
* add yaml output to mongodbflex commands * update docs * Update internal/cmd/mongodbflex/backup/describe/describe.go Co-authored-by: João Palet <[email protected]> * change error log --------- Co-authored-by: João Palet <[email protected]>
1 parent 107b90d commit 41915da

11 files changed

+60
-23
lines changed

docs/stackit_mongodbflex_backup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ stackit mongodbflex backup [flags]
2121
```
2222
-y, --assume-yes If set, skips all confirmation prompts
2323
--async If set, runs the command asynchronously
24-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
24+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
2525
-p, --project-id string Project ID
2626
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
2727
```

docs/stackit_mongodbflex_backup_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ stackit mongodbflex backup describe BACKUP_ID [flags]
3232
```
3333
-y, --assume-yes If set, skips all confirmation prompts
3434
--async If set, runs the command asynchronously
35-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
35+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
3636
-p, --project-id string Project ID
3737
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
3838
```

docs/stackit_mongodbflex_backup_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ stackit mongodbflex backup list [flags]
3636
```
3737
-y, --assume-yes If set, skips all confirmation prompts
3838
--async If set, runs the command asynchronously
39-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
39+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
4040
-p, --project-id string Project ID
4141
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
4242
```

docs/stackit_mongodbflex_backup_restore-jobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ stackit mongodbflex backup restore-jobs [flags]
3636
```
3737
-y, --assume-yes If set, skips all confirmation prompts
3838
--async If set, runs the command asynchronously
39-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
39+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
4040
-p, --project-id string Project ID
4141
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
4242
```

docs/stackit_mongodbflex_backup_restore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ stackit mongodbflex backup restore [flags]
4040
```
4141
-y, --assume-yes If set, skips all confirmation prompts
4242
--async If set, runs the command asynchronously
43-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
43+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
4444
-p, --project-id string Project ID
4545
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
4646
```

docs/stackit_mongodbflex_backup_schedule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ stackit mongodbflex backup schedule [flags]
3232
```
3333
-y, --assume-yes If set, skips all confirmation prompts
3434
--async If set, runs the command asynchronously
35-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
35+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
3636
-p, --project-id string Project ID
3737
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
3838
```

docs/stackit_mongodbflex_backup_update-schedule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ stackit mongodbflex backup update-schedule [flags]
4040
```
4141
-y, --assume-yes If set, skips all confirmation prompts
4242
--async If set, runs the command asynchronously
43-
-o, --output-format string Output format, one of ["json" "pretty" "none"]
43+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
4444
-p, --project-id string Project ID
4545
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
4646
```

internal/cmd/mongodbflex/backup/describe/describe.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77

8+
"github.com/goccy/go-yaml"
89
"github.com/inhies/go-bytesize"
910
"github.com/spf13/cobra"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -129,10 +130,18 @@ func outputResult(p *print.Printer, cmd *cobra.Command, outputFormat, restoreSta
129130
case print.JSONOutputFormat:
130131
details, err := json.MarshalIndent(backup, "", " ")
131132
if err != nil {
132-
return fmt.Errorf("marshal backup for MongoDB Flex backup: %w", err)
133+
return fmt.Errorf("marshal MongoDB Flex backup: %w", err)
133134
}
134135
cmd.Println(string(details))
135136

137+
return nil
138+
case print.YAMLOutputFormat:
139+
details, err := yaml.Marshal(backup)
140+
if err != nil {
141+
return fmt.Errorf("marshal MongoDB Flex backup: %w", err)
142+
}
143+
p.Outputln(string(details))
144+
136145
return nil
137146
default:
138147
table := tables.NewTable()

internal/cmd/mongodbflex/backup/list/list.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77

8+
"github.com/goccy/go-yaml"
89
"github.com/inhies/go-bytesize"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -152,6 +153,14 @@ func outputResult(p *print.Printer, outputFormat string, backups []mongodbflex.B
152153
}
153154
p.Outputln(string(details))
154155

156+
return nil
157+
case print.YAMLOutputFormat:
158+
details, err := yaml.Marshal(backups)
159+
if err != nil {
160+
return fmt.Errorf("marshal MongoDB Flex backups list: %w", err)
161+
}
162+
p.Outputln(string(details))
163+
155164
return nil
156165
default:
157166
table := tables.NewTable()

internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77

8+
"github.com/goccy/go-yaml"
89
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -146,6 +147,14 @@ func outputResult(p *print.Printer, outputFormat string, restoreJobs []mongodbfl
146147
}
147148
p.Outputln(string(details))
148149

150+
return nil
151+
case print.YAMLOutputFormat:
152+
details, err := yaml.Marshal(restoreJobs)
153+
if err != nil {
154+
return fmt.Errorf("marshal MongoDB Flex restore jobs list: %w", err)
155+
}
156+
p.Outputln(string(details))
157+
149158
return nil
150159
default:
151160
table := tables.NewTable()

0 commit comments

Comments
 (0)