From 4f9f7df8255372858b540c67fb5ebd8eac6ca0b9 Mon Sep 17 00:00:00 2001 From: hudson-newey Date: Mon, 30 Sep 2024 21:04:03 +1000 Subject: [PATCH] Add --dry-run flag --- README.md | 9 +++++---- src/patches/rm.go | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8a9f26..a0bf313 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Wraps the rm command with a more secure, safer, and more private version - `--hard` Do not soft-delete file - `--soft` Soft delete a file. A backup will be stored in `/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 ## Features @@ -53,10 +54,10 @@ You can specify what directories are soft-deleted anb hard-deleted by using the # backed up in the `backups` directory backups: /tmp/2rm/ hard: - - node_modules/ - - target/ - - .angular/ - - .next/ + - "node_modules/" + - "target/" + - ".angular/" + - ".next/" # always soft delete backup files, # regardless of it they are configured # for a hard delete diff --git a/src/patches/rm.go b/src/patches/rm.go index db4dc4a..661a6a1 100644 --- a/src/patches/rm.go +++ b/src/patches/rm.go @@ -16,11 +16,13 @@ const TRASH_DIR_PERMISSIONS = 0755 const HARD_DELETE_CLA = "--hard" const SOFT_DELETE_CLA = "--soft" const SILENT_CLA = "--silent" +const DRY_RUN_CLA = "--dry-run" func RmPatch(arguments []string, config models.Config) { forceHardDelete := util.InArray(arguments, HARD_DELETE_CLA) forceSoftDelete := util.InArray(arguments, SOFT_DELETE_CLA) silent := util.InArray(arguments, SILENT_CLA) + dryRun := util.InArray(arguments, DRY_RUN_CLA) actionedArgs := removeUnNeededArguments( removeDangerousArguments(arguments), @@ -43,6 +45,10 @@ func RmPatch(arguments []string, config models.Config) { fmt.Println(debugStatement) } + if dryRun { + return + } + for _, path := range filePaths { absolutePath := relativeToAbsolute(path) isTmp := isTmpPath(absolutePath)