Add ability to delete multiple snapshots separated by comma

This commit is contained in:
yo 2022-07-14 14:00:41 +02:00
parent 9b86d786fe
commit 99f7bed6f3
2 changed files with 8 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import (
)
const (
gVersion = "0.29e"
gVersion = "0.29f"
// TODO : Get from $jail_zpool/defaults.json
MIN_DYN_DEVFS_RULESET = 1000
@ -210,8 +210,8 @@ You can specify multiple jails.`,
snapshotDeleteCmd = &cobra.Command{
Use: "destroy",
Short: "destroy snapshots",
Long: `Destroy snapshot of a jail by specifying snapshot name and jail name.`,
// You can specify multiple jails.`,
Long: `Destroy snapshot of a jail by specifying snapshot name and jail name.
You can specify multiple snapshots separated by comma.`,
Run: func(cmd *cobra.Command, args []string) {
// Load inventory
ListJails(args, false)

View File

@ -230,10 +230,11 @@ func deleteJailSnapshot(jail Jail) error {
for _, line := range strings.Split(out, "\n") {
if len(line) > 0 {
ls := strings.Split(line, "@")
matched, _ := regexp.Match(fmt.Sprintf("^%s(\\/.*)?$", gSnapshotName), []byte(ls[1]))
if matched {
snaptodel = append(snaptodel, strings.Join(ls, "@"))
for _, sn := range strings.Split(gSnapshotName, ",") {
matched, _ := regexp.Match(fmt.Sprintf("^%s(\\/.*)?$", sn), []byte(ls[1]))
if matched {
snaptodel = append(snaptodel, strings.Join(ls, "@"))
}
}
}
}