Go-ing Minimal: Building a CLI Task Manager with Cobra

I am exploring Go lately and wanted to learn this via project-based learning, because it is better than the traditional clearing the fundamentals and knowing the intricate details, having in-depth before starting out.

In order to keep things simple, I wanted to make something that I would use myself, so I decided to make a CLI task manager(why CLI? because I think it is cool)

What does it do?

You can:

  • ➕ Add tasks

  • 🗑️ Remove tasks

  • ✅ Mark them done or pending

  • 🔎 Filter tasks out on the basis of their status

  • 🖋️ Edit the tasks

And not only did I make it for myself, I also made it for anyone wanting to use it, with the help of Cobra(cobra.dev).

Here is the link for anyone curious:
https://github.com/subsavage/Taskmaster

P.S. - This project lives on my GitHub (@subsavage), but you’ll usually find me posting as @hungrydevo on X and Hashnode. Now on with the good stuff…

What I learned?

  • Slices, how these things work and how they are similar, but at the same time different than arrays(I know the juxtaposiion sounds odd, but trust me on this one)

  • File handling, I wanted this project to be cool, but also beginner friendly, so that I don’t keep debugging something I made in 1-2 days for a week, just to figure out I overcomplicated things for myself, but I/O in go is clean to be honest, pretty straight-forward

  • Using cobra and feeling cool, cobra is a little intimadating to use because it changes your simple code with 3 simple .go files to something you would see in starred repos real quick, so quick, it scared me before it made me feel good

  • One last interesting thing I learned was that if you have to use your functions across files in Go, you have to write their names in PascalCase, else it did’nt work

How I learned?

This is something that helped me a lot in this project, instead of following a tutorial, I used ChatGPT to help me, and here is how I went about it:

  • I opened two different chats:

    • one to help me structure and tell what’s next in the code

    • one for asking questions and doubts about the code that I was writing

This approach helped me, but note one thing if you also want to try this approach, you will have to be extra-alert whenever you sit down and make the project, because of GPT giving you the code directly can make you reconsider your decision of learning the hard way, and honestly, nobody likes it in the short term, and it makes it really easy to go auto-pilot and start copy pasting code.

Conclusion

The project is small, but it made me understand Go way better than I would have understood by just reading documentations or blindly following coding tutorials. Though I am not someone ecperienced, I would really recommend anyone wanting to learn Go, to try this projet out for themselves instead of making their first project a complicated microservice using RAD, vector databases and then quitting not even halfway. Anyways gotta get Go-ing(yes, pun intended).

Thanks for reading!
Feel free to drop feedback, questions, or ideas in the comments. Or just let me know if you tried it!

#golang #cli #buildinpublic #devlog #hashnode #taskmanager

2
Subscribe to my newsletter

Read articles from Harshit Srivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harshit Srivastava
Harshit Srivastava