From 48928b9e753a1cda7b533b1fad063d0ad916250f Mon Sep 17 00:00:00 2001
From: Florent Gluck <florent.gluck@hesge.ch>
Date: Wed, 20 Jul 2022 22:56:59 +0200
Subject: [PATCH] Added more sanity checks

---
 src/client_cli/cmdVM/vmCred2pdf.go  | 5 +++++
 src/client_cli/cmdVM/vmDel.go       | 5 +++++
 src/client_cli/cmdVM/vmDelAccess.go | 5 +++++
 src/client_cli/cmdVM/vmEdit.go      | 5 +++++
 src/client_cli/cmdVM/vmSetAccess.go | 5 +++++
 src/client_cli/cmdVM/vmStart.go     | 5 +++++
 src/client_cli/cmdVM/vmStop.go      | 5 +++++
 7 files changed, 35 insertions(+)

diff --git a/src/client_cli/cmdVM/vmCred2pdf.go b/src/client_cli/cmdVM/vmCred2pdf.go
index 53f90f4..6cb6ba0 100644
--- a/src/client_cli/cmdVM/vmCred2pdf.go
+++ b/src/client_cli/cmdVM/vmCred2pdf.go
@@ -46,6 +46,11 @@ func (cmd *Cred2pdf)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to retrieve credentials from!")
+		return 1
+	}
+
 	const leftMargin = 4.
 	const topMargin = 4.
 	const rightMargin = 0.
diff --git a/src/client_cli/cmdVM/vmDel.go b/src/client_cli/cmdVM/vmDel.go
index 033d829..918fd6f 100644
--- a/src/client_cli/cmdVM/vmDel.go
+++ b/src/client_cli/cmdVM/vmDel.go
@@ -37,6 +37,11 @@ func (cmd *Del)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to delete!")
+		return 1
+	}
+
 	statusCode := 0
 
 	for _, vm := range(vms) {
diff --git a/src/client_cli/cmdVM/vmDelAccess.go b/src/client_cli/cmdVM/vmDelAccess.go
index 30398e2..8e33cf0 100644
--- a/src/client_cli/cmdVM/vmDelAccess.go
+++ b/src/client_cli/cmdVM/vmDelAccess.go
@@ -58,6 +58,11 @@ func (cmd *DelAccess)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to delete user's VM access!")
+		return 1
+	}
+
 	statusCode := 0
 
 	for _, vm := range(vms) {
diff --git a/src/client_cli/cmdVM/vmEdit.go b/src/client_cli/cmdVM/vmEdit.go
index dfea71e..2da5383 100644
--- a/src/client_cli/cmdVM/vmEdit.go
+++ b/src/client_cli/cmdVM/vmEdit.go
@@ -71,6 +71,11 @@ func (cmd *Edit)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to edit!")
+		return 1
+	}
+
 	statusCode := 0
 
 	for _, vm := range(vms) {
diff --git a/src/client_cli/cmdVM/vmSetAccess.go b/src/client_cli/cmdVM/vmSetAccess.go
index 5d8ba08..58d0d57 100644
--- a/src/client_cli/cmdVM/vmSetAccess.go
+++ b/src/client_cli/cmdVM/vmSetAccess.go
@@ -55,6 +55,11 @@ func (cmd *SetAccess)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to set user's VM access!")
+		return 1
+	}
+
 	type vmAccessForUserArgs struct {
 		Access map[string]int `json:"access"  validate:"required"`
 	}
diff --git a/src/client_cli/cmdVM/vmStart.go b/src/client_cli/cmdVM/vmStart.go
index a80a72b..172e9f7 100644
--- a/src/client_cli/cmdVM/vmStart.go
+++ b/src/client_cli/cmdVM/vmStart.go
@@ -37,6 +37,11 @@ func (cmd *Start)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to start!")
+		return 1
+	}
+
 	statusCode := 0
 
 	for _, vm := range(vms) {
diff --git a/src/client_cli/cmdVM/vmStop.go b/src/client_cli/cmdVM/vmStop.go
index c1dfe81..132ca23 100644
--- a/src/client_cli/cmdVM/vmStop.go
+++ b/src/client_cli/cmdVM/vmStop.go
@@ -37,6 +37,11 @@ func (cmd *Stop)Run(args []string) int {
 		return 1
 	}
 
+	if len(vms) == 0 {
+		u.PrintlnErr("No VMs to stop!")
+		return 1
+	}
+
 	statusCode := 0
 
 	for _, vm := range(vms) {
-- 
GitLab