Midterm Project: Build a Real CLI Tool

মিডটার্ম প্রোজেক্ট — একটি বাস্তব CLI টুল তৈরি করুন

Suggested: 3–5 hours Intermediate 1 project · 4 tracks Milestone

1. Ship Something Real

You have learned the core of Python. Now it is time to build a project that actually runs — something you can show on GitHub, use yourself, and keep improving. You will pick one of four tracks, design it, code it, test it, document it, and publish it.

আপনি Python-এর মূল অংশ শিখে ফেলেছেন। এবার এমন একটি প্রোজেক্ট তৈরির পালা যা সত্যিই চলবে — যেটি আপনি GitHub-এ দেখাতে পারবেন, নিজে ব্যবহার করতে পারবেন, এবং ভবিষ্যতে উন্নত করতে পারবেন। চারটি track থেকে একটি বেছে নিন, design করুন, code করুন, test করুন, document করুন এবং publish করুন।
Why CLI? Command-line tools are the simplest way to ship real software. No web browser, no frontend, no deployment — just Python and stdin/stdout. Every serious developer has a small CLI collection.

2. Choose Your Track

Track A — Todo Manager
Add, list, complete, delete todos. Store in a JSON file.
Bangla: কাজের তালিকা ব্যবস্থাপনা।
Track B — Password Generator
Secure passwords with length, symbol, digit options.
Bangla: নিরাপদ পাসওয়ার্ড জেনারেটর।
Track C — Bulk File Renamer
Rename files by pattern in a directory — with dry-run mode.
Bangla: পাইকারি ফাইল পুনঃনামকরণ।
Track D — CSV Statistics
Read a CSV, compute mean/median/min/max per column.
Bangla: CSV পরিসংখ্যান।

3. Core Skills You'll Apply

  • argparse for parsing command-line arguments
  • File I/O — reading and writing JSON or text
  • Functions with clear signatures and docstrings
  • Error handling — try/except, exit codes
  • Multi-file structure — separate logic from CLI
  • README.md — installation, usage, examples

4. argparse Quick Primer

argparse turns a Python script into a professional CLI in a dozen lines — with --help, default values, type checking, and subcommands.

argparse_demo.py
import argparse

parser = argparse.ArgumentParser(description="Greet someone")
parser.add_argument("name", help="person's name")
parser.add_argument("--loud", action="store_true", help="shout")
parser.add_argument("--times", type=int, default=1)

# In a real CLI: args = parser.parse_args()
# Here we simulate a call for the demo:
args = parser.parse_args(["Ayesha", "--times", "3", "--loud"])

greeting = f"Hello, {args.name}!"
if args.loud:
    greeting = greeting.upper()

for _ in range(args.times):
    print(greeting)

5. Example: Track A Skeleton (Todo Manager)

todo.py
import json
from pathlib import Path

DATA = Path("todos.json")

def load():
    if DATA.exists():
        return json.loads(DATA.read_text())
    return []

def save(items):
    DATA.write_text(json.dumps(items, indent=2))

def add(text):
    items = load()
    items.append({"text": text, "done": False})
    save(items)
    print(f"Added: {text}")

def list_all():
    for i, t in enumerate(load(), 1):
        mark = "✔" if t["done"] else " "
        print(f"{i}. [{mark}] {t['text']}")

# Demo run
add("Finish Module 19")
add("Push to GitHub")
list_all()

Wrap this logic in an argparse front-end with subcommands add, list, done N, delete N, and you have a full CLI todo manager.

6. Deliverables Checklist

Must haveNice to have
README.md with install + usageLogging
requirements.txt (even if empty)Config file (.ini, .toml)
Works with --helpBasic tests (module 29 will cover)
Handles bad input gracefullyColor output with rich or ANSI codes
On GitHub with a clear commit historyPackaged with pipx

7. Vocabulary (শব্দভাণ্ডার)

TermMeaningবাংলায়
CLICommand-line interface.কমান্ড-লাইন ইন্টারফেস।
argparseStdlib module for parsing CLI args.CLI argument parse করার stdlib module।
SubcommandA secondary verb (git add, git commit).দ্বিতীয়-স্তরের command (যেমন git add)।
Exit code0 = success, non-zero = error.0 = সফল, অন্য কিছু = error।
Dry runShow what would happen without doing it.কী হতে যাচ্ছে দেখানো, কিন্তু বাস্তবে না করা।

8. Mini-Exercises Before You Start

  1. Write an argparse-based script that sums two numbers passed on the command line.
    argparse দিয়ে দুটি সংখ্যা যোগ করার script লিখুন।
    ✨ Show Answer (উত্তর দেখুন)
    ans1.py
    import argparse
    p = argparse.ArgumentParser()
    p.add_argument("a", type=int)
    p.add_argument("b", type=int)
    args = p.parse_args(["7", "12"])   # simulated
    print(args.a + args.b)
  2. Write a function that writes a list of dicts to a JSON file.
    Dict-এর একটি list-কে JSON ফাইলে লেখার ফাংশন লিখুন।
    ✨ Show Answer (উত্তর দেখুন)
    ans2.py
    import json
    def save_json(path, data):
        with open(path, "w") as f:
            json.dump(data, f, indent=2)
    
    save_json("/tmp/demo.json", [{"id": 1, "text": "hello"}])
    print(open("/tmp/demo.json").read())
  3. Draft the top-level module layout for your chosen track (folder/file names only).
    আপনার বেছে নেওয়া track-এর top-level folder/file structure লিখুন।
    ✨ Show Answer (উত্তর দেখুন)

    Example for Track A:

    todo-cli/
    ├── todo/
    │   ├── __init__.py
    │   ├── storage.py    # load/save JSON
    │   └── cli.py        # argparse entry point
    ├── tests/
    │   └── test_storage.py
    ├── README.md
    └── requirements.txt
  4. Write a password generator that accepts length and returns a random string.
    Length-ভিত্তিক random password generator ফাংশন লিখুন।
    ✨ Show Answer (উত্তর দেখুন)
    ans4.py
    import secrets, string
    
    def password(n=16):
        alphabet = string.ascii_letters + string.digits + "!@#$%^&*"
        return "".join(secrets.choice(alphabet) for _ in range(n))
    
    print(password(12))
  5. Write a README outline for your project (just the section headings).
    প্রোজেক্টের README-এর section heading-গুলো লিখুন।
    ✨ Show Answer (উত্তর দেখুন)

    A solid README structure:

    # Project Name
    
    A one-line tagline.
    
    ## Installation
    ## Quick Start
    ## Commands / Usage
    ## Examples
    ## Configuration
    ## Development / Testing
    ## License

Summary — Module 19

Pick one of the four tracks, scope it small, ship it. A working small project is worth far more than an ambitious abandoned one. By the end of this module you should have a GitHub repo with a README, a runnable script, and at least one real user (you).

চারটি track-এর যেকোনো একটি বেছে নিন, scope ছোট রাখুন, ship করুন। একটি ছোট কিন্তু চলমান প্রোজেক্ট — ambitious কিন্তু অসম্পূর্ণ প্রোজেক্টের চেয়ে অনেক বেশি মূল্যবান। এই module শেষে GitHub-এ একটি README ও runnable script-সহ repo থাকা উচিত, এবং অন্তত একজন ব্যবহারকারী (আপনি নিজেই)।

Next Module → File I/O — text, binary, CSV, JSON।