Skip to content

A feature-rich command-line task manager built with Go. Created as a learning exercise to explore Go's features and best practices.

License

Notifications You must be signed in to change notification settings

rhmnaulia/go-cli-task-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go CLI Task Manager

A feature-rich command-line task manager built with Go. This project was created as a learning exercise to explore Go's features and best practices. Each component is thoroughly documented with comments to explain the implementation details and Go concepts used.

Learning Goals

This project demonstrates several important Go concepts and patterns:

  • 📚 Package Organization: How to structure a Go project with multiple packages
  • 🔒 Concurrency: Using mutexes for thread-safe operations
  • 💾 File I/O: JSON serialization and persistent storage
  • 🧪 Testing: Table-driven tests and test coverage
  • 🎯 CLI Development: Using cobra for command-line interfaces
  • 📝 Documentation: Comprehensive code comments explaining implementation details
  • Performance: Efficient data structures and algorithms
  • 🔧 Error Handling: Proper error handling patterns in Go

Features

  • ✨ Add tasks with titles and descriptions
  • 📅 Set due dates for tasks
  • ⭐ Assign priority levels (high, medium, low)
  • 🏷️ Add tags for better organization
  • 📋 List tasks with powerful filtering and sorting options
  • ✓ Mark tasks as complete
  • 🗑️ Delete tasks
  • 💾 Persistent storage using JSON
  • 🔒 Thread-safe operations

Installation

Prerequisites

  • Go 1.21 or higher

Getting Started

  1. Clone the repository:

    git clone https://github.com/rahmanaulia/go-cli-task-manager.git
    cd go-cli-task-manager
  2. Install dependencies:

    go mod tidy
  3. Build the project:

    go build

Project Structure

.
├── cmd_test.go          # Command tests with examples of testing CLI applications
├── go.mod              # Go module file
├── go.sum              # Go module checksums
├── main.go            # Entry point with cobra CLI setup
├── storage/           # Storage package demonstrating data persistence
│   ├── storage.go    # Task storage with mutex for thread safety
│   └── storage_test.go # Storage tests showing Go testing patterns
├── task.go           # Task commands showing cobra CLI patterns
└── types/            # Type definitions showing Go type system
    └── task.go      # Task struct with JSON tags and validation

Each file contains detailed comments explaining:

  • The purpose of each package and file
  • Implementation details and design decisions
  • Go patterns and best practices used
  • Error handling strategies
  • Concurrency considerations

Usage

Adding Tasks

Basic task:

./go-cli-task-manager add "Buy groceries" "Get milk and eggs"

Task with due date, priority, and tags:

./go-cli-task-manager add "Important meeting" "Team sync" -d 2024-03-30 -p high -t work,urgent

Listing Tasks

List all tasks:

./go-cli-task-manager list

Filter by tag:

./go-cli-task-manager list -t work

Filter by state:

./go-cli-task-manager list -s pending

Sort tasks:

./go-cli-task-manager list -o priority  # Sort by priority
./go-cli-task-manager list -o due       # Sort by due date

Managing Tasks

Mark task as complete:

./go-cli-task-manager complete 1

Delete a task:

./go-cli-task-manager delete 1

Data Storage

Tasks are stored in a JSON file located at ~/.taskmanager/tasks.json. The storage implementation demonstrates:

  • File I/O operations in Go
  • JSON marshaling/unmarshaling
  • Error handling for file operations
  • Thread-safe access using mutexes

Development

Running Tests

The test suite demonstrates various testing patterns in Go:

Run all tests:

go test -v ./...

Run tests with coverage:

go test -v -cover ./...

Key Learning Points

  1. Package Organization

    • Separation of concerns
    • Interface design
    • Package visibility rules
  2. Concurrency

    • Mutex usage
    • Thread-safe operations
    • Race condition prevention
  3. Error Handling

    • Error wrapping
    • Custom error types
    • Graceful error recovery
  4. Testing

    • Table-driven tests
    • Test fixtures
    • Mock interfaces

Contributing

This project is primarily for learning purposes, but contributions that help demonstrate additional Go concepts are welcome:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Add detailed comments explaining the Go concepts used
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A feature-rich command-line task manager built with Go. Created as a learning exercise to explore Go's features and best practices.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages