44 "context"
55 "fmt"
66
7+ "github.com/alibaba/pouch/apis/types"
8+
79 "github.com/spf13/cobra"
810)
911
@@ -18,7 +20,8 @@ be released.
1820// RmCommand is used to implement 'rm' command.
1921type RmCommand struct {
2022 baseCommand
21- force bool
23+ force bool
24+ removeVolumes bool
2225}
2326
2427// Init initializes RmCommand command.
@@ -39,16 +42,24 @@ func (r *RmCommand) Init(c *Cli) {
3942
4043// addFlags adds flags for specific command.
4144func (r * RmCommand ) addFlags () {
42- r .cmd .Flags ().BoolVarP (& r .force , "force" , "f" , false , "if the container is running, force to remove it" )
45+ flagSet := r .cmd .Flags ()
46+
47+ flagSet .BoolVarP (& r .force , "force" , "f" , false , "if the container is running, force to remove it" )
48+ flagSet .BoolVarP (& r .removeVolumes , "volumes" , "v" , false , "remove container's volumes that create by the container" )
4349}
4450
4551// runRm is the entry of RmCommand command.
4652func (r * RmCommand ) runRm (args []string ) error {
4753 ctx := context .Background ()
4854 apiClient := r .cli .Client ()
4955
56+ options := & types.ContainerRemoveOptions {
57+ Force : r .force ,
58+ Volumes : r .removeVolumes ,
59+ }
60+
5061 for _ , name := range args {
51- if err := apiClient .ContainerRemove (ctx , name , r . force ); err != nil {
62+ if err := apiClient .ContainerRemove (ctx , name , options ); err != nil {
5263 return fmt .Errorf ("failed to remove container: %v" , err )
5364 }
5465 fmt .Printf ("%s\n " , name )
0 commit comments