4
4
"context"
5
5
"flag"
6
6
"os"
7
+ "path/filepath"
7
8
"time"
8
9
9
10
"go.coder.com/cli"
@@ -14,8 +15,9 @@ import (
14
15
type rmcmd struct {
15
16
gf * globalFlags
16
17
17
- repoArg string
18
- all bool
18
+ repoArg string
19
+ all bool
20
+ withData bool
19
21
}
20
22
21
23
func (c * rmcmd ) Spec () cli.CommandSpec {
@@ -29,22 +31,22 @@ or all of the containers on a system with the -all flag.`,
29
31
}
30
32
31
33
func (c * rmcmd ) RegisterFlags (fl * flag.FlagSet ) {
32
- fl .BoolVar (& c .all , "all" , false , "Remove all sail containers." )
34
+ fl .BoolVar (& c .all , "all" , false , "Remove all Sail containers." )
35
+ fl .BoolVar (& c .withData , "with-data" , false , "Remove the cloned repository's directory." )
33
36
}
34
37
35
38
func (c * rmcmd ) Run (fl * flag.FlagSet ) {
36
- c .gf .ensureDockerDaemon ()
37
-
38
39
c .repoArg = fl .Arg (0 )
39
40
40
41
if c .repoArg == "" && ! c .all {
41
42
fl .Usage ()
42
43
os .Exit (1 )
43
44
}
44
45
45
- names := c . getRemovalList ()
46
+ c . gf . ensureDockerDaemon ()
46
47
47
- removeContainers (names ... )
48
+ names := c .getRemovalList ()
49
+ c .removeContainers (names ... )
48
50
}
49
51
50
52
// getRemovalList returns a list of container names that should be removed.
@@ -74,7 +76,7 @@ func (c *rmcmd) getRemovalList() []string {
74
76
return names
75
77
}
76
78
77
- func removeContainers (names ... string ) {
79
+ func ( c * rmcmd ) removeContainers (names ... string ) {
78
80
cli := dockerClient ()
79
81
defer cli .Close ()
80
82
@@ -87,7 +89,14 @@ func removeContainers(names ...string) {
87
89
flog .Error ("failed to remove %s: %v" , name , err )
88
90
continue
89
91
}
90
-
92
+ if c .withData {
93
+ root := c .gf .config ().ProjectRoot
94
+ path := filepath .Join (root , c .repoArg )
95
+ err = os .RemoveAll (path )
96
+ if err != nil {
97
+ flog .Error ("Failed to remove cloned directory: %v" , err )
98
+ }
99
+ }
91
100
flog .Info ("removed %s" , name )
92
101
}
93
102
}
0 commit comments