44 "fmt"
55 "os"
66 "path/filepath"
7+ "strings"
78
89 "github.com/steady-bytes/draft/tools/dctl/docker"
910 "github.com/steady-bytes/draft/tools/dctl/output"
@@ -22,46 +23,54 @@ func Clean(cmd *cobra.Command, args []string) (err error) {
2223 config , err := getInfraConfig (name )
2324 if err != nil {
2425 output .Error (err )
25- return err
26+ continue
27+ }
28+
29+ err = dockerCtl .StopContainerByName (ctx , containerName (name ))
30+ if err != nil && ! strings .Contains (err .Error (), "not found" ) {
31+ output .Error (err )
2632 }
2733
2834 err = dockerCtl .RemoveContainerByName (ctx , containerName (name ))
29- if err != nil {
35+ if err != nil && ! strings . Contains ( err . Error (), "not found" ) {
3036 output .Error (err )
3137 }
3238
33- if config .configFile != nil {
34- output .Print ("Deleting configuration file for: %s" , name )
35- home , err := os .UserHomeDir ()
36- if err != nil {
37- output .Error (err )
38- os .Exit (1 )
39- }
39+ if Full {
40+ if config .configFile != nil {
41+ output .Print ("Deleting configuration file for: %s" , name )
42+ home , err := os .UserHomeDir ()
43+ if err != nil {
44+ output .Error (err )
45+ continue
46+ }
4047
41- dirName := filepath .Join (home , ".config" , "dctl" , "infra" )
42- fileName := filepath .Join (dirName , fmt .Sprintf ("%s.yaml" , name ))
43- err = os .Remove (fileName )
44- if err != nil {
45- output .Error (err )
46- os .Exit (1 )
48+ dirName := filepath .Join (home , ".config" , "dctl" , "infra" )
49+ fileName := filepath .Join (dirName , fmt .Sprintf ("%s.yaml" , name ))
50+ err = os .Remove (fileName )
51+ if err != nil && ! os .IsNotExist (err ) {
52+ output .Error (err )
53+ continue
54+ }
4755 }
48- }
4956
50- if config .mountPoint != nil {
51- output .Print ("Deleting volume for: %s" , name )
52- home , err := os .UserHomeDir ()
53- if err != nil {
54- output .Error (err )
55- os . Exit ( 1 )
56- }
57+ if config .mountPoint != nil {
58+ output .Print ("Deleting volume for: %s" , name )
59+ home , err := os .UserHomeDir ()
60+ if err != nil {
61+ output .Error (err )
62+ continue
63+ }
5764
58- dirName := filepath .Join (home , ".config" , "dctl" , "infra" , name )
59- err = os .RemoveAll (dirName )
60- if err != nil {
61- output .Error (err )
62- os .Exit (1 )
65+ dirName := filepath .Join (home , ".config" , "dctl" , "infra" , name )
66+ err = os .RemoveAll (dirName )
67+ if err != nil {
68+ output .Error (err )
69+ continue
70+ }
6371 }
6472 }
73+
6574 }
6675
6776 return nil
0 commit comments