Skip to content

Commit

Permalink
Add --help and --version flags
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Nov 2, 2024
1 parent 0017aa4 commit 4f6ab06
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ const NOTIFICATION_CLA = "--notify"

// gnu rm CLI arguments
const INTERACTIVE_CLA = "-i"
const HELP_CLA = "--help"
const VERSION_CLA = "--version"
39 changes: 39 additions & 0 deletions src/cli/docs.go
Original file line number Diff line number Diff line change
@@ -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)
}
25 changes: 8 additions & 17 deletions src/patches/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 4f6ab06

Please sign in to comment.