diff --git a/README.md b/README.md index c709844..0d7bf2f 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,31 @@ A wrapper for the "rm" command with soft-deletes, config-based deletion, debug information, and saner defaults +## "GNU Like" command line arguments + +- `-i` Interactivly prompt before each deletion request +- `--help` Display help information (without deletion) +- `--version` Display version information (without deletion) + ## Additional command line arguments - `--overwrite` Overwrite the disk location location with zeros - `--hard` Do not soft-delete file -- `--soft` Soft delete a file. A backup will be stored in `/tmp/2rm` +- `--soft` Soft delete a file and store a backup (default `/tmp/2rm`) - `--silent` Do not print out additional information priduced by 2rm. This is useful for scripting situations - `--dry-run` Perform a dry run and show all the files that would be deleted - `--bypass-protected` Using this flag will allow you to delete a file protected by the 2rm config - `--notify` Send a system notification once deletion is complete +- `--force` Bypass protections ## Unsupported command line arguments - `-r`, `-R`, `--recursive` Recursively delete a directory of files -- `-d` Only delete empty directories -- `-v` Emit additional verbose information +- `-d`, `--dir` Only delete empty directories +- `-v`, `--verbose` Emit additional verbose information - `--version` Show version information - `--help` Show help information +- `-I` Prompt if deleting more than three files - `--interactive[=WHEN]` Interactive with a custom threshold - `--one-file-system` Do not allow cross-file-system deletes - `-f`, `--force` (partially implemented) diff --git a/src/cli/args.go b/src/cli/args.go index c709aae..35cb905 100644 --- a/src/cli/args.go +++ b/src/cli/args.go @@ -11,3 +11,5 @@ const NOTIFICATION_CLA = "--notify" // gnu rm CLI arguments const INTERACTIVE_CLA = "-i" +const HELP_CLA = "--help" +const VERSION_CLA = "--version" diff --git a/src/cli/docs.go b/src/cli/docs.go new file mode 100644 index 0000000..a13cd87 --- /dev/null +++ b/src/cli/docs.go @@ -0,0 +1,39 @@ +package cli + +import "fmt" + +const VERSION = "2rm 0.1.0" + +const HELP_DOCS = ` +Usage: rm [OPTION]... [FILE]... +Mark FILE(s) for deletion. + +"GNU Like" OPTION(s): +-i Prompt before every deletion request +--force Bypass 2rm protections + +2rm OPTION(s) Flags: +--overwrite Overwrite the disk location location with zeros +--hard Do not soft-delete FILE(s) +--soft Soft delete a file and a store backup (default /tmp/2rm) +--silent Do not print out additional information priduced by 2rm. This is useful for scripting situations +--dry-run Perform a dry run and show all the files that would be deleted +--bypass-protected Using this flag will allow you to delete a file protected by the 2rm config +--notify Send a system notification once deletion is complete + +By default, 2rm will soft-delete a file and store a backup (default /tmp/2rm) + +You can create a 2rm config file under ~/.local/share/2rm/config.yml that will +allow you to protect files/directories, set a custom backup location, and +configure directories that should always be hard-deleted. + +Use "man 2rm" for more information. +` + +func PrintVersion() { + fmt.Println(VERSION) +} + +func PrintHelp() { + fmt.Print(HELP_DOCS) +} diff --git a/src/patches/rm.go b/src/patches/rm.go index 2747185..69889bc 100644 --- a/src/patches/rm.go +++ b/src/patches/rm.go @@ -25,13 +25,18 @@ func RmPatch(arguments []string, config models.Config) { overwrite := util.InArray(arguments, cli.OVERWRITE_CLA) shouldNotify := util.InArray(arguments, cli.NOTIFICATION_CLA) + requestingHelp := util.InArray(arguments, cli.HELP_CLA) + requestingVersion := util.InArray(arguments, cli.VERSION_CLA) + actionedArgs := removeUnNeededArguments( removeDangerousArguments(arguments), ) - if shouldPassthrough(actionedArgs) { - command := "rm " + strings.Join(actionedArgs, " ") - util.Execute(command) + if requestingHelp { + cli.PrintHelp() + return + } else if requestingVersion { + cli.PrintVersion() return } @@ -89,20 +94,6 @@ func RmPatch(arguments []string, config models.Config) { } } -// sometimes we want to pass through the arguments to the original rm command -// e.g. when executing --help or --version -func shouldPassthrough(arguments []string) bool { - passthroughArguments := []string{"--help", "--version"} - - for _, arg := range arguments { - if util.InArray(passthroughArguments, arg) { - return true - } - } - - return false -} - func removeUnNeededArguments(arguments []string) []string { returnedArguments := []string{} unNeededArguments := []string{