@@ -19,10 +19,12 @@ import (
1919 "fmt"
2020 "os"
2121
22+ "github.com/spf13/cast"
2223 "github.com/spf13/cobra"
2324
25+ "github.com/liquidweb/liquidweb-cli/instance"
2426 "github.com/liquidweb/liquidweb-cli/types/api"
25- "github.com/liquidweb/liquidweb-cli/validate "
27+ "github.com/liquidweb/liquidweb-cli/utils "
2628)
2729
2830var cloudServerDestroyCmdUniqIdFlag []string
@@ -40,25 +42,54 @@ server.`,
4042 reasonFlag , _ := cmd .Flags ().GetString ("reason" )
4143 forceFlag , _ := cmd .Flags ().GetBool ("force" )
4244
43- // if force flag wasn't passed
44- if ! forceFlag {
45- // exit if user didn't consent
46- if proceed := dialogDesctructiveConfirmProceed (); ! proceed {
47- os .Exit (0 )
45+ destroyTargets := map [string ]interface {}{}
46+
47+ if forceFlag {
48+ for _ , uniqId := range cloudServerDestroyCmdUniqIdFlag {
49+ destroyTargets [uniqId ] = "" // didnt do lookup, so dont know hostname
50+ }
51+ } else {
52+ methodArgs := instance.AllPaginatedResultsArgs {
53+ Method : "bleed/storm/server/list" ,
54+ ResultsPerPage : 100 ,
55+ }
56+ results , err := lwCliInst .AllPaginatedResults (& methodArgs )
57+ if err != nil {
58+ lwCliInst .Die (err )
4859 }
49- }
5060
51- for _ , uniqId := range cloudServerDestroyCmdUniqIdFlag {
61+ for _ , item := range results .Items {
62+ uniqId := cast .ToString (item ["uniq_id" ])
63+ var shouldDestroy bool
64+ for _ , candidateUniqId := range cloudServerDestroyCmdUniqIdFlag {
65+ if uniqId == candidateUniqId {
66+ shouldDestroy = true
67+ break
68+ }
69+ }
70+
71+ if shouldDestroy {
72+ destroyTargets [uniqId ] = cast .ToString (item ["domain" ])
73+ }
74+ }
5275
53- validateFields := map [ interface {}] interface {} {
54- uniqId : "UniqId" ,
76+ if len ( destroyTargets ) == 0 {
77+ lwCliInst . Die ( fmt . Errorf ( "no Cloud Servers found to destroy" ))
5578 }
5679
57- if err := validate .Validate (validateFields ); err != nil {
58- fmt .Printf ("%s ... skipping\n " , err )
59- continue
80+ utils .PrintYellow ("DANGER! " )
81+ utils .PrintRed ("This will destroy ALL Cloud Servers listed below:\n \n " )
82+ for uniqId , hostname := range destroyTargets {
83+ fmt .Printf ("\t uniq_id: %s hostname: %s\n " , uniqId , hostname )
6084 }
85+ fmt .Println ("" )
6186
87+ if proceed := dialogDesctructiveConfirmProceed (); ! proceed {
88+ os .Exit (0 )
89+ }
90+ }
91+
92+ for uniqId , hostname := range destroyTargets {
6293 destroyArgs := map [string ]interface {}{
6394 "uniq_id" : uniqId ,
6495 "cancellation_comment" : commentFlag ,
@@ -74,7 +105,11 @@ server.`,
74105 lwCliInst .Die (err )
75106 }
76107
77- fmt .Printf ("destroyed: %s\n " , destroyed .Destroyed )
108+ if hostname == "" {
109+ fmt .Printf ("destroyed: %s\n " , destroyed .Destroyed )
110+ } else {
111+ fmt .Printf ("destroyed: %s (%s)\n " , destroyed .Destroyed , hostname )
112+ }
78113 }
79114 },
80115}
0 commit comments