Skip to content

Commit

Permalink
Add -v and --verbose flags
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Nov 2, 2024
1 parent ede28f3 commit 8a484e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A wrapper for the "rm" command with soft-deletes, config-based deletion, debug i
- `-i` Interactivly prompt before each deletion request
- `-I` Prompt if deleting more than the interactive threshold of files (default 3)
- `-r`, `-R`, `--recursive` Recursively delete a directory of files
- `-v`, `--verbose` Emit additional verbose information
- `--help` Display help information (without deletion)
- `--version` Display version information (without deletion)

Expand All @@ -26,9 +27,6 @@ A wrapper for the "rm" command with soft-deletes, config-based deletion, debug i
## Unsupported command line arguments

- `-d`, `--dir` Only delete empty directories
- `-v`, `--verbose` Emit additional verbose information
- `--version` Show version information
- `--help` Show help information
- `--interactive[=WHEN]` Interactive with a custom threshold
- `--one-file-system` Do not allow cross-file-system deletes
- `-f`, `--force` Bypass protections
Expand Down
3 changes: 3 additions & 0 deletions src/cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const BYPASS_PROTECTED_CLA = "--bypass-protected"
const OVERWRITE_CLA = "--overwrite"
const NOTIFICATION_CLA = "--notify"

const VERBOSE_CLA = "--verbose"
const VERBOSE_SHORT_CLA = "-v"

// gnu rm CLI arguments
const INTERACTIVE_CLA = "-i"
const INTERACTIVE_GROUP_CLA = "-I"
Expand Down
8 changes: 8 additions & 0 deletions src/cli/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ Mark FILE(s) for deletion.
"GNU Like" OPTION(s):
-i Prompt before every deletion request
-r, -R, --recursive Remove directories and their contents recursively
-I Prompt once before deleting more than the interactive
threshold (default 3)
-f, --force Bypass protections
-v, --verbose Add additional information to the output
--help Display this help and (without deleting anything)
--version Output version information (without deleting anything)
2rm OPTION(s) Flags:
--overwrite Overwrite the disk location location with zeros
Expand Down
10 changes: 10 additions & 0 deletions src/patches/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,18 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
forceSoftDelete := util.InArray(arguments, cli.SOFT_DELETE_CLA)
bypassProtected := util.InArray(arguments, cli.BYPASS_PROTECTED_CLA)
overwrite := util.InArray(arguments, cli.OVERWRITE_CLA)
silent := util.InArray(arguments, cli.SILENT_CLA)

hasInteraciveCla := util.InArray(arguments, cli.INTERACTIVE_CLA)
hasGroupInteractiveCla := util.InArray(arguments, cli.INTERACTIVE_GROUP_CLA)
isInteractiveGroup := hasGroupInteractiveCla && len(paths) >= config.InteractiveThreshold()
isInteractive := hasInteraciveCla || isInteractiveGroup

hasVerboseCla := util.InArray(arguments, cli.VERBOSE_CLA)
if !hasVerboseCla {
hasVerboseCla = util.InArray(arguments, cli.VERBOSE_SHORT_CLA)
}

for _, path := range paths {
if isInteractive {
fmt.Println("Are you sure you want to delete", path, "? (y/n)")
Expand Down Expand Up @@ -159,6 +165,10 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
shouldHardDelete := isTmp || forceHardDelete || isConfigHardDelete && !isConfigSoftDelete && !forceSoftDelete

deletePath(absolutePath, shouldHardDelete, config)

if hasVerboseCla && !silent {
fmt.Printf("removed '%s'\n", path)
}
}
}

Expand Down

0 comments on commit 8a484e5

Please sign in to comment.