DEV Community

Muhammad Syuqri
Muhammad Syuqri

Posted on

saferm - A tool to safely remove files on CLI

Introduction

I started this toy project to learn about Golang and have some experience using it. Test-Driven Development and GitHub Actions were side learning points for this project.

I have been doing development in the past which did not prioritise automated testing. As a result, extensive manual testing at the end of each development iteration was required and it definitely was a pain. I wanted to take a different approach and learn the methodology behind TDD so that each iteration of the development process can go through automated testing and can be published with confidence.

I decided to go into GitHub Actions by submitting my first GitHub Action - Newbiefy (Wacky Wildcards Category) - as part of the DEV x GitHub Actions Hackathon. This toy project builds on the knowledge from that experience.

What is saferm?

You know when you want to delete a repository from GitHub, they ask for the name of the repository as confirmation of the deletion so that they know it is by choice, not accident? saferm does exactly that when you are trying to remove files from a directory using the command-line. Each file it discovers will prompt the user to input the filename before deletion.

Why saferm?

Apart from the learning reasons as mentioned before, there is one thing that I found in the rm command.

The conventional rm command does have an interactive mode using the -i flag. However, this only prompts the user for a Y/y + Enter response.

The purpose of saferm is to make the deletion process more painstaking so that the user will take ownership of the deletion.

Check it out here

GitHub logo Dansyuqri / saferm

This repository is a project for me to explore Go.

saferm

A command-line tool for removing files from a directory in a safe fashion. Written in Go.

Installation

First, install or update the saferm binary into you $GOPATH like so:

$ go get -u github.com/dansyuqri/saferm

Usage

You can immediately use the saferm command on your cli.

$ saferm

By default, the saferm works on the current working directory. In order to specify another directory, you will need to supplement the -p flag like so:

$ saferm -p /home/user/Downloads

The above command immediately starts giving you a filename for you to input in order to delete the file:

$ saferm -p /home/user/Downloads
Enter filename to confirm deletion
testfile.txt

Once you have entered the exact filename, it will proceed to delete the file. This painstaking process of typing the exact name of the file will assure you that the deletion is by choice, not accident (similar to how deletion of a repository…

Conclusion

Definitely open to feedback and suggestions, be it on the code or TDD methodology that I was trying to adopt. Leave them below thank you!

Top comments (0)