Skip to content

Latest commit

 

History

History

01_cli_apps

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

CLI Applications - Console-Based Projects

Projects that run in the terminal/console, perfect for learning fundamentals.


Project Ideas

1. Todo List Manager

Difficulty: Beginner Time: 10-15 hours

A command-line todo application with file persistence.

Features:

  • Add, remove, edit todos
  • Mark as complete/incomplete
  • Save/load from file
  • List all/completed/pending
  • Search todos
  • Categories/tags

Key Concepts:

  • Class design
  • STL containers (vector, string)
  • File I/O
  • User input handling
  • Command parsing

File Structure:

todo_app/
├── src/
│   ├── main.cpp
│   ├── todo.cpp
│   ├── todo.h
│   ├── todo_manager.cpp
│   └── todo_manager.h
├── data/
│   └── todos.txt
└── CMakeLists.txt

2. Address Book

Difficulty: Beginner-Intermediate Time: 15-20 hours

Contact management system with search capabilities.

Features:

  • Add/remove/edit contacts
  • Search by name, phone, email
  • Import/export CSV
  • Sort by various fields
  • Multiple address books
  • Backup/restore

Key Concepts:

  • OOP design
  • STL algorithms
  • File parsing (CSV)
  • String manipulation
  • Search algorithms

File Structure:

address_book/
├── src/
│   ├── main.cpp
│   ├── contact.cpp
│   ├── contact.h
│   ├── address_book.cpp
│   ├── address_book.h
│   ├── csv_handler.cpp
│   └── csv_handler.h
└── data/
    └── contacts.csv

3. Text Editor

Difficulty: Intermediate Time: 25-35 hours

Simple console-based text editor.

Features:

  • Open/save files
  • Edit text
  • Navigation
  • Search/replace
  • Undo/redo
  • Syntax highlighting (basic)

Key Concepts:

  • String handling
  • Terminal control
  • File operations
  • Buffer management
  • Command pattern

File Structure:

text_editor/
├── src/
│   ├── main.cpp
│   ├── editor.cpp
│   ├── editor.h
│   ├── buffer.cpp
│   ├── buffer.h
│   ├── terminal.cpp
│   └── terminal.h
└── CMakeLists.txt

4. Personal Finance Tracker

Difficulty: Intermediate Time: 20-30 hours

Track income, expenses, and generate reports.

Features:

  • Add transactions (income/expense)
  • Categorize transactions
  • Monthly reports
  • Budget tracking
  • Export to CSV
  • Charts/visualization (text-based)

Key Concepts:

  • Data models
  • Date/time handling
  • Statistics
  • Report generation
  • Data persistence

File Structure:

finance_tracker/
├── src/
│   ├── main.cpp
│   ├── transaction.cpp
│   ├── transaction.h
│   ├── tracker.cpp
│   ├── tracker.h
│   ├── reports.cpp
│   └── reports.h
└── data/
    └── transactions.json

5. Password Manager

Difficulty: Intermediate-Advanced Time: 30-40 hours

Secure password storage with encryption.

Features:

  • Store passwords
  • Generate random passwords
  • Encrypt database
  • Search passwords
  • Copy to clipboard
  • Password strength checker

Key Concepts:

  • Cryptography (basic)
  • Security best practices
  • Secure storage
  • String handling
  • Clipboard operations

File Structure:

password_manager/
├── src/
│   ├── main.cpp
│   ├── password.cpp
│   ├── password.h
│   ├── vault.cpp
│   ├── vault.h
│   ├── crypto.cpp
│   └── crypto.h
└── data/
    └── vault.enc

CLI Framework Template

Basic Structure

// cli_app.h
#ifndef CLI_APP_H
#define CLI_APP_H

#include <string>
#include <vector>

class CLIApp {
public:
    CLIApp(const std::string& name, const std::string& version);

    void run();

private:
    void printWelcome();
    void printHelp();
    void processCommand(const std::string& cmd);

    std::string appName_;
    std::string version_;
    bool running_;
};

#endif // CLI_APP_H
// cli_app.cpp
#include "cli_app.h"
#include <iostream>
#include <sstream>

CLIApp::CLIApp(const std::string& name, const std::string& version)
    : appName_(name), version_(version), running_(true) {
}

void CLIApp::run() {
    printWelcome();

    std::string line;
    while (running_) {
        std::cout << "> ";
        std::getline(std::cin, line);

        if (!line.empty()) {
            processCommand(line);
        }
    }
}

void CLIApp::printWelcome() {
    std::cout << appName_ << " v" << version_ << "\n";
    std::cout << "Type 'help' for commands\n\n";
}

void CLIApp::printHelp() {
    std::cout << "Available commands:\n";
    std::cout << "  help    - Show this help\n";
    std::cout << "  version - Show version\n";
    std::cout << "  exit    - Exit application\n";
}

void CLIApp::processCommand(const std::string& cmd) {
    std::istringstream iss(cmd);
    std::string command;
    iss >> command;

    if (command == "help") {
        printHelp();
    } else if (command == "version") {
        std::cout << appName_ << " v" << version_ << "\n";
    } else if (command == "exit") {
        running_ = false;
        std::cout << "Goodbye!\n";
    } else {
        std::cout << "Unknown command: " << command << "\n";
        std::cout << "Type 'help' for available commands\n";
    }
}
// main.cpp
#include "cli_app.h"

int main() {
    CLIApp app("MyApp", "1.0.0");
    app.run();
    return 0;
}

CLI Best Practices

1. Command Structure

// Parse: command [arg1] [arg2] [options]
struct Command {
    std::string name;
    std::vector<std::string> args;
    std::map<std::string, std::string> options;
};

Command parseCommand(const std::string& input);

2. Output Formatting

// Use consistent formatting
std::cout << std::left << std::setw(20) << "Name"
          << std::setw(10) << "Value" << "\n";
std::cout << std::string(30, '-') << "\n";

3. Input Validation

// Always validate user input
if (input.empty() || input.size() > MAX_LENGTH) {
    std::cerr << "Invalid input\n";
    return;
}

4. Error Handling

// Provide helpful error messages
try {
    // Operation
} catch (const std::exception& e) {
    std::cerr << "Error: " << e.what() << "\n";
}

Testing CLI Applications

1. Unit Tests

  • Test each command handler
  • Test validation logic
  • Test data operations

2. Integration Tests

  • Test command sequences
  • Test file operations
  • Test error recovery

3. Manual Testing

  • Walk through all features
  • Test edge cases
  • Test with various inputs

Building and Packaging

CMake Template

cmake_minimum_required(VERSION 3.30)
project(MyCLIApp VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Executable
add_executable(my_cli_app
    src/main.cpp
    src/cli_app.cpp
)

target_include_directories(my_cli_app
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src
)

Next Steps

  1. Choose project - Pick from list above
  2. Plan features - Define MVP
  3. Set up project - Create directory structure
  4. Implement - Build feature by feature
  5. Test - Verify all functionality
  6. Document - Write README
  7. Share - Put on GitHub

Ready to start? Pick a project and begin coding! 🚀