Added help and exit

This commit is contained in:
2026-04-27 12:15:58 -04:00
parent 47a6796e1c
commit 7b2bb509ec
13 changed files with 103 additions and 23 deletions

View File

@@ -1,5 +1,33 @@
from pathlib import Path
import shutil
def main(args):
for item in args:
Path(args).unlink(missing_ok=True) # missing_ok=True prevents error if file is missing
if not args:
print("remove: no arguments were given")
return
# Check for the -rf flag
recursive = False
if "-rf" in args:
recursive = True
args.remove("-rf") # Remove flag from list so only paths remain
if args == ["-h"] or args == ["--help"]:
print("remove: Use -rf to delete directories and their contents.")
else:
for item in args:
path = Path(item)
if not path.exists():
continue # 'force' usually means ignore non-existent files
try:
if path.is_dir():
if recursive:
shutil.rmtree(path) # This is the "recursive" part
else:
print(f"remove: cannot remove '{item}': Is a directory")
else:
path.unlink() # Delete individual file
except Exception as e:
print(f"remove: error deleting {item}: {e}")