Skip to content

Commit

Permalink
Merge pull request #82 from swemarx/delete-snapshots
Browse files Browse the repository at this point in the history
Added cli code for "snapshot delete"
  • Loading branch information
Nick Canzoneri authored Nov 13, 2020
2 parents b448aa7 + 0dd923f commit 7bcffaa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions pkg/cli/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func init() {
setupRestoreSubCommand()
setupListSubCommand()
setupCreateSubCommand()
setupDeleteSubCommand()

rootCmd.AddCommand(cmdSnapshot)
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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("Delete operation called successfully.")
},
}

0 comments on commit 7bcffaa

Please sign in to comment.