Browse Source

add force flag to host/node delete

Matthew R Kasun 2 years ago
parent
commit
fa3f33d4d0
4 changed files with 16 additions and 4 deletions
  1. 4 1
      cli/cmd/host/delete.go
  2. 4 1
      cli/cmd/node/delete.go
  3. 4 1
      cli/functions/host.go
  4. 4 1
      cli/functions/node.go

+ 4 - 1
cli/cmd/host/delete.go

@@ -5,16 +5,19 @@ import (
 	"github.com/spf13/cobra"
 )
 
+var force bool
+
 var hostDeleteCmd = &cobra.Command{
 	Use:   "delete HostID",
 	Args:  cobra.ExactArgs(1),
 	Short: "Delete a host",
 	Long:  `Delete a host`,
 	Run: func(cmd *cobra.Command, args []string) {
-		functions.PrettyPrint(functions.DeleteHost(args[0]))
+		functions.PrettyPrint(functions.DeleteHost(args[0], force))
 	},
 }
 
 func init() {
 	rootCmd.AddCommand(hostDeleteCmd)
+	hostDeleteCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "delete even if part of network(s)")
 }

+ 4 - 1
cli/cmd/node/delete.go

@@ -5,16 +5,19 @@ import (
 	"github.com/spf13/cobra"
 )
 
+var force bool
+
 var nodeDeleteCmd = &cobra.Command{
 	Use:   "delete [NETWORK NAME] [NODE ID]",
 	Args:  cobra.ExactArgs(2),
 	Short: "Delete a Node",
 	Long:  `Delete a Node`,
 	Run: func(cmd *cobra.Command, args []string) {
-		functions.PrettyPrint(functions.DeleteNode(args[0], args[1]))
+		functions.PrettyPrint(functions.DeleteNode(args[0], args[1], force))
 	},
 }
 
 func init() {
 	rootCmd.AddCommand(nodeDeleteCmd)
+	nodeDeleteCmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "force delete a node")
 }

+ 4 - 1
cli/functions/host.go

@@ -17,7 +17,10 @@ func GetHosts() *[]models.ApiHost {
 }
 
 // DeleteHost - delete a host
-func DeleteHost(hostID string) *models.ApiHost {
+func DeleteHost(hostID string, force bool) *models.ApiHost {
+	if force {
+		return request[models.ApiHost](http.MethodDelete, "/api/hosts/"+hostID+"?force=true", nil)
+	}
 	return request[models.ApiHost](http.MethodDelete, "/api/hosts/"+hostID, nil)
 }
 

+ 4 - 1
cli/functions/node.go

@@ -27,7 +27,10 @@ func UpdateNode(networkName, nodeID string, node *models.ApiNode) *models.ApiNod
 }
 
 // DeleteNode - delete a node
-func DeleteNode(networkName, nodeID string) *models.SuccessResponse {
+func DeleteNode(networkName, nodeID string, force bool) *models.SuccessResponse {
+	if force {
+		return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s/?force=true", networkName, nodeID), nil)
+	}
 	return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s", networkName, nodeID), nil)
 }