From 15adee05069e3470a9733c2cf95669436f88a253 Mon Sep 17 00:00:00 2001 From: pauhull Date: Thu, 19 Oct 2023 13:08:59 +0200 Subject: [PATCH] feat(server): add --enable-backup flag to "create" command (#568) As requested in #488 --- internal/cmd/server/create.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/cmd/server/create.go b/internal/cmd/server/create.go index 42082793..39f2df11 100644 --- a/internal/cmd/server/create.go +++ b/internal/cmd/server/create.go @@ -81,6 +81,8 @@ var CreateCmd = base.Cmd{ cmd.Flags().StringSlice("enable-protection", []string{}, "Enable protection (delete, rebuild) (default: none)") cmd.RegisterFlagCompletionFunc("enable-protection", cmpl.SuggestCandidates("delete", "rebuild")) + cmd.Flags().Bool("enable-backup", false, "Enable automatic backups") + return cmd }, @@ -112,6 +114,20 @@ var CreateCmd = base.Cmd{ return err } + enableBackup, _ := cmd.Flags().GetBool("enable-backup") + if enableBackup { + action, _, err := client.Server().EnableBackup(ctx, server, "") + if err != nil { + return err + } + + if err := actionWaiter.ActionProgress(ctx, action); err != nil { + return err + } + + fmt.Printf("Backups enabled for server %d\n", server.ID) + } + if !server.PublicNet.IPv4.IsUnspecified() { fmt.Printf("IPv4: %s\n", server.PublicNet.IPv4.IP.String()) }