DEV Community

Cover image for Create a simple CLI, a mess
Jairo Fernández
Jairo Fernández

Posted on • Edited on

Create a simple CLI, a mess

In all my different jobs and personal projects, whenever I needed to create some kind of console application for any purpose, I always started from scratch. I used bash scripting, Cobra (Golang), Commander.js (Node.js), and even Dart and PHP. However, I always ended up with a bad taste in my mouth. Why? Starting the process is terrible 😩 (I guess the best starting point is with Cobra 😅). Checking the structure, discussing the correct place for the code, or simply putting all the code into a copy-paste example with 1000 options turns this simple task into a mess… 🤯

Aha, I decided to contribute to the chaos by creating my own library in Node.js. However, I have a strong stance about node_modules, I haven’t felt good about the huge size for simple things: too many testing frameworks, compilers, etc. I recently heard about Node.js LTS (20), which allows you to use the native testing library. I thought, I can support typeScript and @types/node as dev dependencies. It’s not perfect, but it’s just two dependencies.

The next challenge for me was configuring the CI, unit testing, and dealing with the garbage produced by GPT-4 trying to help me create this as an experiment, which ended really well 😅. (Don’t kill me in the future, AI, I am faithful to the machine cause 🤖.) But I need to recognize that this work would have been impossible to do without using GPT-4o in just one week! After my normal job, with a lot of coffee ☕, so thanks, GPT-4o! 😄

Which characteristics do I need from a CLI maker, that is the name of the library

  1. I need to start from zero with just one command; I hate to copy, paste, and rethink the same stupid things 🤦‍♂️
  2. I need a simple structure supporting TypeScript.
  3. I need a simple CI with GitHub Actions automatically set up.
  4. I need the CLI exportable automatically.
  5. I need to use my library like a simple package with and npm install and import in other parts.
  6. I need support for an interactive CLI. I love the Symfony terminal—interactive, fast, great UX or something similar to Gum
  7. I need to use the CLI in a direct mode passing the parameters.
  8. I need simple types, I want to add emails, url, list and use them easily
  9. I don’t want to configure 1 million dev dependencies
  10. I want to see my commands and not want to vomit because of the mess 🤢

Yeah, I'm not picky, but I wanted something like this for myself 😅.

So, hands of work, I would like to present you cli-maker my own version of the hell, just execute this command and check the magic,

Go to an empty directory and use Node 20 (I’ll add this validation, I promise you 😉)

Go to library if you want to skip this lecture npm @ideascol/cli-maker

npx @ideascol/cli-maker
Enter fullscreen mode Exit fullscreen mode

And that’s it, you will see the usual installation process. Please be patient 😊.

Image description

Trust me, proceed… 😉

Image description

For now, I just have one command—the only one needed for now. Please proceed in an empty folder and fill in the data 😊.

Image description

Right! Now, create your own CLI 🚀.

npx @ideascol/cli-maker create
Enter fullscreen mode Exit fullscreen mode

Image description

Fill data

Image description

If all was good, you’ll see this:

Image description

Let me explain to you in the next article how we can extract the best from this simple library… 📚✨

See you! 👋

Check the next cli-maker-more-than-we-see

Top comments (1)

Collapse
 
andres_fernandez_05a8738d profile image
Andres Fernandez

Awesome , thanks for sharing 👏🏻.