Browse Source

add force flag to host/node delete (#2548)

* add force flag to host/node delete

* review comments

---------

Co-authored-by: Abhishek K <[email protected]>
Matthew R Kasun 1 year ago
parent
commit
823182cf09
4 changed files with 12 additions and 6 deletions
  1. 4 1
      cli/cmd/host/delete.go
  2. 4 1
      cli/cmd/node/delete.go
  3. 2 2
      cli/functions/host.go
  4. 2 2
      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")
 }

+ 2 - 2
cli/functions/host.go

@@ -17,8 +17,8 @@ func GetHosts() *[]models.ApiHost {
 }
 
 // DeleteHost - delete a host
-func DeleteHost(hostID string) *models.ApiHost {
-	return request[models.ApiHost](http.MethodDelete, "/api/hosts/"+hostID, nil)
+func DeleteHost(hostID string, force bool) *models.ApiHost {
+	return request[models.ApiHost](http.MethodDelete, fmt.Sprintf("/api/hosts/%s?force=%t", hostID, force), nil)
 }
 
 // UpdateHost - update a host

+ 2 - 2
cli/functions/node.go

@@ -27,8 +27,8 @@ func UpdateNode(networkName, nodeID string, node *models.ApiNode) *models.ApiNod
 }
 
 // DeleteNode - delete a node
-func DeleteNode(networkName, nodeID string) *models.SuccessResponse {
-	return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s", networkName, nodeID), nil)
+func DeleteNode(networkName, nodeID string, force bool) *models.SuccessResponse {
+	return request[models.SuccessResponse](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s?force=%t", networkName, nodeID, force), nil)
 }
 
 // CreateEgress - turn a node into an egress