Skip to content

Commit 4f6ab06

Browse files
committed
Add --help and --version flags
1 parent 0017aa4 commit 4f6ab06

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@
44

55
A wrapper for the "rm" command with soft-deletes, config-based deletion, debug information, and saner defaults
66

7+
## "GNU Like" command line arguments
8+
9+
- `-i` Interactivly prompt before each deletion request
10+
- `--help` Display help information (without deletion)
11+
- `--version` Display version information (without deletion)
12+
713
## Additional command line arguments
814

915
- `--overwrite` Overwrite the disk location location with zeros
1016
- `--hard` Do not soft-delete file
11-
- `--soft` Soft delete a file. A backup will be stored in `/tmp/2rm`
17+
- `--soft` Soft delete a file and store a backup (default `/tmp/2rm`)
1218
- `--silent` Do not print out additional information priduced by 2rm. This is useful for scripting situations
1319
- `--dry-run` Perform a dry run and show all the files that would be deleted
1420
- `--bypass-protected` Using this flag will allow you to delete a file protected by the 2rm config
1521
- `--notify` Send a system notification once deletion is complete
22+
- `--force` Bypass protections
1623

1724
## Unsupported command line arguments
1825

1926
- `-r`, `-R`, `--recursive` Recursively delete a directory of files
20-
- `-d` Only delete empty directories
21-
- `-v` Emit additional verbose information
27+
- `-d`, `--dir` Only delete empty directories
28+
- `-v`, `--verbose` Emit additional verbose information
2229
- `--version` Show version information
2330
- `--help` Show help information
31+
- `-I` Prompt if deleting more than three files
2432
- `--interactive[=WHEN]` Interactive with a custom threshold
2533
- `--one-file-system` Do not allow cross-file-system deletes
2634
- `-f`, `--force` (partially implemented)

src/cli/args.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ const NOTIFICATION_CLA = "--notify"
1111

1212
// gnu rm CLI arguments
1313
const INTERACTIVE_CLA = "-i"
14+
const HELP_CLA = "--help"
15+
const VERSION_CLA = "--version"

src/cli/docs.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cli
2+
3+
import "fmt"
4+
5+
const VERSION = "2rm 0.1.0"
6+
7+
const HELP_DOCS = `
8+
Usage: rm [OPTION]... [FILE]...
9+
Mark FILE(s) for deletion.
10+
11+
"GNU Like" OPTION(s):
12+
-i Prompt before every deletion request
13+
--force Bypass 2rm protections
14+
15+
2rm OPTION(s) Flags:
16+
--overwrite Overwrite the disk location location with zeros
17+
--hard Do not soft-delete FILE(s)
18+
--soft Soft delete a file and a store backup (default /tmp/2rm)
19+
--silent Do not print out additional information priduced by 2rm. This is useful for scripting situations
20+
--dry-run Perform a dry run and show all the files that would be deleted
21+
--bypass-protected Using this flag will allow you to delete a file protected by the 2rm config
22+
--notify Send a system notification once deletion is complete
23+
24+
By default, 2rm will soft-delete a file and store a backup (default /tmp/2rm)
25+
26+
You can create a 2rm config file under ~/.local/share/2rm/config.yml that will
27+
allow you to protect files/directories, set a custom backup location, and
28+
configure directories that should always be hard-deleted.
29+
30+
Use "man 2rm" for more information.
31+
`
32+
33+
func PrintVersion() {
34+
fmt.Println(VERSION)
35+
}
36+
37+
func PrintHelp() {
38+
fmt.Print(HELP_DOCS)
39+
}

src/patches/rm.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ func RmPatch(arguments []string, config models.Config) {
2525
overwrite := util.InArray(arguments, cli.OVERWRITE_CLA)
2626
shouldNotify := util.InArray(arguments, cli.NOTIFICATION_CLA)
2727

28+
requestingHelp := util.InArray(arguments, cli.HELP_CLA)
29+
requestingVersion := util.InArray(arguments, cli.VERSION_CLA)
30+
2831
actionedArgs := removeUnNeededArguments(
2932
removeDangerousArguments(arguments),
3033
)
3134

32-
if shouldPassthrough(actionedArgs) {
33-
command := "rm " + strings.Join(actionedArgs, " ")
34-
util.Execute(command)
35+
if requestingHelp {
36+
cli.PrintHelp()
37+
return
38+
} else if requestingVersion {
39+
cli.PrintVersion()
3540
return
3641
}
3742

@@ -89,20 +94,6 @@ func RmPatch(arguments []string, config models.Config) {
8994
}
9095
}
9196

92-
// sometimes we want to pass through the arguments to the original rm command
93-
// e.g. when executing --help or --version
94-
func shouldPassthrough(arguments []string) bool {
95-
passthroughArguments := []string{"--help", "--version"}
96-
97-
for _, arg := range arguments {
98-
if util.InArray(passthroughArguments, arg) {
99-
return true
100-
}
101-
}
102-
103-
return false
104-
}
105-
10697
func removeUnNeededArguments(arguments []string) []string {
10798
returnedArguments := []string{}
10899
unNeededArguments := []string{

0 commit comments

Comments
 (0)