Skip to content

Commit 05a04ee

Browse files
committed
Add -I flag threshold config option
1 parent 56b41fc commit 05a04ee

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A wrapper for the "rm" command with soft-deletes, config-based deletion, debug i
77
## "GNU Like" command line arguments
88

99
- `-i` Interactivly prompt before each deletion request
10-
- `-I` Prompt if deleting more three files
10+
- `-I` Prompt if deleting more than the interactive threshold of files (default 3)
1111
- `--help` Display help information (without deletion)
1212
- `--version` Display version information (without deletion)
1313

@@ -117,4 +117,9 @@ soft:
117117
# accidental deletion through 2rm
118118
protected:
119119
- ".ssh/"
120+
# when using the -I flag without any arguments, the user will be prompted
121+
# for confirmation before deleting each file if the number of files is
122+
# greater or equal to this threshold
123+
# default is 3 files/directories
124+
interactive: 10
120125
```

src/cli/docs.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Mark FILE(s) for deletion.
1111
"GNU Like" OPTION(s):
1212
-i Prompt before every deletion request
1313
14-
-I Prompt once before deleting more than three files
14+
-I Prompt once before deleting more than the interactive
15+
threshold (default 3)
1516
1617
-f, --force Bypass protections
1718

src/config/parse_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestParsingConfig(t *testing.T) {
4141
Protected: []string{
4242
".ssh/",
4343
},
44+
Interactive: 10,
4445
}
4546

4647
assertConfig(t, "valid.yml", expectedConfig)

src/models/config.go

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ type Config struct {
2626
// any file paths that match these patterns will be protected from deletion
2727
// protected files cannot be deleted without the --bypass-protected flag
2828
Protected []string
29+
30+
// when using the -I flag without any arguments, the user will be prompted
31+
// for confirmation before deleting each file if the number of files is
32+
// greater or equal to this threshold
33+
// default is 3 files/directories
34+
Interactive int
2935
}
3036

3137
func (config Config) ShouldHardDelete(path string) bool {
@@ -77,6 +83,16 @@ func (config Config) SoftDeleteDir() string {
7783
return "/tmp/2rm/"
7884
}
7985

86+
func (config Config) InteractiveThreshold() int {
87+
const DEFAULT_INTERACTIVE_THRESHOLD = 3
88+
89+
if config.Interactive == 0 {
90+
return DEFAULT_INTERACTIVE_THRESHOLD
91+
}
92+
93+
return config.Interactive
94+
}
95+
8096
func matchesPattern(pattern string, path string) bool {
8197
// we put a wildcard at the start so that we don't have to match full
8298
// paths

src/patches/rm.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
)
1616

1717
const TRASH_DIR_PERMISSIONS = 0755
18-
const INTERACTIVE_THRESHOLD = 3
1918

2019
func RmPatch(arguments []string, config models.Config) {
2120
silent := util.InArray(arguments, cli.SILENT_CLA)
@@ -117,7 +116,7 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
117116

118117
hasInteraciveCla := util.InArray(arguments, cli.INTERACTIVE_CLA)
119118
hasGroupInteractiveCla := util.InArray(arguments, cli.INTERACTIVE_GROUP_CLA)
120-
isInteractiveGroup := hasGroupInteractiveCla && len(paths) >= INTERACTIVE_THRESHOLD
119+
isInteractiveGroup := hasGroupInteractiveCla && len(paths) >= config.InteractiveThreshold()
121120
isInteractive := hasInteraciveCla || isInteractiveGroup
122121

123122
for _, path := range paths {

tests/assets/configs/valid.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ soft:
1111
- "*.bak"
1212
protected:
1313
- ".ssh/"
14+
interactive: 10

0 commit comments

Comments
 (0)