From 471f0e645935a7d180a366976f306f8e5a6e2d85 Mon Sep 17 00:00:00 2001 From: swemarx Date: Thu, 12 Nov 2020 15:46:29 +0100 Subject: [PATCH 1/2] Added cli code for "snapshot delete" --- go.mod | 2 -- pkg/cli/snapshot.go | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index e53fa7f..d72d5b0 100644 --- a/go.mod +++ b/go.mod @@ -18,14 +18,12 @@ require ( github.com/pelletier/go-toml v1.8.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rakyll/gotest v0.0.5 // indirect - github.com/smartystreets/goconvey v1.6.4 // indirect github.com/spf13/afero v1.4.0 // indirect github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cobra v1.0.0 github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.7.1 - github.com/stretchr/testify v1.4.0 // indirect github.com/tidwall/gjson v1.6.1 github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect golang.org/x/net v0.0.0-20200927032502-5d4f70055728 // indirect diff --git a/pkg/cli/snapshot.go b/pkg/cli/snapshot.go index e16e563..0bcbf85 100644 --- a/pkg/cli/snapshot.go +++ b/pkg/cli/snapshot.go @@ -14,6 +14,7 @@ func init() { setupRestoreSubCommand() setupListSubCommand() setupCreateSubCommand() + setupDeleteSubCommand() rootCmd.AddCommand(cmdSnapshot) } @@ -63,6 +64,23 @@ func setupCreateSubCommand() { cmdSnapshot.AddCommand(cmdSnapshotCreate) } +func setupDeleteSubCommand() { + cmdSnapshotDelete.Flags().StringP("snapshot", "s", "", "Snapshot name to query (required)") + err := cmdSnapshotDelete.MarkFlagRequired("snapshot") + if err != nil { + fmt.Printf("Error binding snapshot configuration flag: %s \n", err) + os.Exit(1) + } + + cmdSnapshotDelete.Flags().StringP("repository", "r", "", "Snapshot repository to query (required)") + err = cmdSnapshotCreate.MarkFlagRequired("repository") + if err != nil { + fmt.Printf("Error binding repository configuration flag: %s \n", err) + os.Exit(1) + } + + cmdSnapshot.AddCommand(cmdSnapshotDelete) +} func setupListSubCommand() { cmdSnapshotList.Flags().StringP("repository", "r", "", "Snapshot repository to query (required)") err := cmdSnapshotList.MarkFlagRequired("repository") @@ -286,3 +304,32 @@ var cmdSnapshotCreate = &cobra.Command{ } }, } + +var cmdSnapshotDelete = &cobra.Command{ + Use: "delete", + Short: "Delete a snapshot.", + Long: `This command will delete a snapshot of the data.`, + Run: func(cmd *cobra.Command, args []string) { + + v := getClient() + + snapshotName, err := cmd.Flags().GetString("snapshot") + if err != nil { + fmt.Printf("Could not retrieve required argument: snapshot. Error: %s\n", err) + os.Exit(1) + } + + repository, err := cmd.Flags().GetString("repository") + if err != nil { + fmt.Printf("Could not retrieve required argument: repository. Error: %s\n", err) + os.Exit(1) + } + + err = v.DeleteSnapshot(repository, snapshotName) + if err != nil { + fmt.Printf("Error while deleting snapshot. Error: %s\n", err) + os.Exit(1) + } + fmt.Println("Snapshot operation started.") + }, +} From 0dd923f5b0fa56938b804da85321d24e5864362f Mon Sep 17 00:00:00 2001 From: swemarx Date: Fri, 13 Nov 2020 08:14:04 +0100 Subject: [PATCH 2/2] Improved informative output --- pkg/cli/snapshot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/snapshot.go b/pkg/cli/snapshot.go index 0bcbf85..f8c3147 100644 --- a/pkg/cli/snapshot.go +++ b/pkg/cli/snapshot.go @@ -330,6 +330,6 @@ var cmdSnapshotDelete = &cobra.Command{ fmt.Printf("Error while deleting snapshot. Error: %s\n", err) os.Exit(1) } - fmt.Println("Snapshot operation started.") + fmt.Println("Delete operation called successfully.") }, }