Skip to content

Commit

Permalink
feat(command): add force flag for files rm
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <[email protected]>
  • Loading branch information
overbool committed Oct 3, 2018
1 parent 78b8e6e commit 16b8423
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ Remove files or directories.
},
Options: []cmdkit.Option{
cmdkit.BoolOption("recursive", "r", "Recursively remove directories."),
cmdkit.BoolOption("force", "Allow to remove anything else"),
},
Run: func(req oldcmds.Request, res oldcmds.Response) {
defer res.SetOutput(nil)
Expand Down Expand Up @@ -1042,6 +1043,7 @@ Remove files or directories.
}

dashr, _, _ := req.Option("r").Bool()
force, _, _ := req.Option("force").Bool()

var success bool
defer func() {
Expand All @@ -1055,7 +1057,7 @@ Remove files or directories.
}()

// if '-r' specified, don't check file type (in bad scenarios, the block may not exist)
if dashr {
if dashr || force {
err := pdir.Unlink(name)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
Expand Down

0 comments on commit 16b8423

Please sign in to comment.