Skip to main content
In this lesson we build several small, focused CLI utilities to show how quickly useful command-line tools can be scaffolded in different languages. The examples alternate between Python, Go, and C++ to demonstrate differences in ergonomics, deployment, and performance. Each example includes a runnable implementation, usage examples, and notes on why you might pick one language over another for a particular task. Table of contents:
  • Python: Project structure generator
  • Vue demo: the generated app
  • Go: CSV → JSON converter
  • C++: Password generator (macOS)
  • Why CLI utilities are useful
  • Links and references

1) Python — Project Structure Generator

Goal: create a small Python CLI script, project_generator.py, that generates boilerplate project folders in a dist/ directory. This generator keeps things simple and file-system focused — no external dependencies required. Supported project types:
  • html — generates index.html, style.css, and scripts.js
  • vue — generates a minimal Vue-style app (simple index.html, style.css, app.js)
Example usage:
How it works (concise implementation):
What you get: running the HTML generator creates a small styled page with a hero section and a button wired to scripts.js. This is a simple, editable starting point suitable for demos or rapid prototyping.
A browser screenshot showing a "Welcome to My HTML Project" page with a large "Hello, World!" card, a "Click Me" button, and an "About This Project" section. The page is displayed over a code editor workspace in the background.
Test the generator’s help and argument validation:
Invalid choices are reported by argparse:
Prefer running generators from a virtual environment or a controlled project directory to avoid accidentally writing files in the wrong place.

2) Vue demo (the generated app)

The Vue-style generator produces a minimal client-side demo: a counter and a tiny todo list implemented in plain JavaScript. The intent is demonstration, not a full Vue build pipeline — you can later migrate the generated files to a modern Vue project if you want to add components, bundling, or state management. Test and extend:
  • Open dist/<project>/index.html in a browser to interact with the demo.
  • Edit app.js to add features, then port into a Vue CLI / Vite setup if you need a build toolchain.
A browser screenshot of a "My Vue.js App" page showing a "Counter Example" (Count: 2) with Increment/Decrement/Reset buttons and a "Simple Todo" section containing an input, Add button, and two todo items each with Remove buttons.

3) Go — CSV to JSON CLI

Goal: implement a small Go CLI (example name csv-to-json or main.go) that reads data/contacts.csv and outputs JSON to stdout. Add a -limit flag to restrict the number of returned records. If -limit is omitted, return all records. Usage:
Concise main.go example:
Notes:
  • This example assumes a CSV header id,first_name,last_name,job_title,email.
  • Flags: -limit to cap results and -file to point to another CSV.
  • The program pretty-prints JSON to stdout so you can pipe or redirect it easily.
Example commands:
Why Go for small CLIs:
  • Single static binary output (deployable without runtime)
  • Fast build times and simple dependency model
  • Strong standard library for encoding/IO tasks

4) C++ — Password generator CLI (macOS)

Goal: build passgen, a small C++ CLI that emits secure-looking passwords. Options:
  • -l, --length (default 16)
  • -c, --count (how many passwords to print)
  • --no-symbols (omit symbol characters)
  • --help
Important security note: this example seeds a PRNG using std::random_device and uses std::mt19937. std::mt19937 is fast and suitable for many tasks, but it is not cryptographically secure. For production-grade passwords, use an OS-provided CSPRNG (e.g., arc4random_buf on BSD/macOS or getrandom on Linux) or a dedicated crypto library.
This example uses std::mt19937 seeded with std::random_device. For production-grade cryptographic passwords, use an OS-provided CSPRNG or a cryptographic library (std::mt19937 is not cryptographically secure).
Compact passgen.cpp (POSIX/macOS-friendly):
Makefile (macOS clang++):
Usage:

Quick comparison: when to use which language


Why CLI utilities are useful

  1. Automation: batch process files, convert formats, and apply transformations programmatically.
  2. CI/CD integration: use micro-utilities for formatting, validation, conversion (CSV → JSON), and other pipeline tasks.
  3. Portability: compiled tools (Go/C++) can be easily distributed as single binaries; scripts (Python) are quick to iterate on.
This lesson demonstrates that small, well-scoped CLIs can be created quickly and evolve into production-grade tools with additions like testing, logging, packaging, and secure random sources. If you want any example expanded — for example, unit tests for the Python generator, a packaged Go binary with module setup, or a C++ version that uses OS CSPRNG APIs — tell me which one and I’ll add the details.

Watch Video