My Go CLI is a command-line tool built in Go that showcases advanced development techniques such as configuration management, logging, error handling, Dockerization, and unit testing. This project is built step-by-step, with each commit demonstrating a new feature or concept.
- Basic command handling using Cobra
- Configuration management with Viper
- Structured logging with Zap
- Advanced error handling
- Unit testing with Go's testing package
- Dockerized CLI for easy distribution
To get started with My Go CLI, clone this repository and ensure you have Go installed.
git clone https://github.com/JorkDev/my-go-cli.git
cd my-go-cli
go mod tidyRun the CLI directly from the terminal:
go run main.gomycli echo [text]: Echoes the input text back to the terminal.mycli version: Prints the current version of the CLI.
To run the CLI using Docker, follow these steps:
docker build -t my-go-cli .docker run --rm my-go-cli echo "Hello, Docker!"This will execute the echo command inside the container. You can also run the default command:
docker run --rm my-go-climy-go-cli/
├── cmd/ # Command definitions
│ ├── root.go
│ └── echo.go
│ └── echo_test.go # File for unit tests
├── config/ # Configuration files and setup
│ └── config.go
├── internal/ # Internal packages, such as logging
│ └── logger.go
├── config.yaml # Default configuration file
├── main.go # Main entry point of the CLI
├── Dockerfile # Docker configuration file
├── README.md # Project description and instructions
├── go.mod # Go module file
└── LICENSE # License file
If you'd like to contribute to My Go CLI, feel free to fork the repository, make some changes, and submit a pull request. All contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for more information.
This project is divided into several phases. Each phase adds more complexity and advanced features:
- Basic CLI Skeleton: Initialize a basic Cobra-based CLI.
- Command Handling: Add commands and flags with Cobra.
- Configuration Management: Integrate Viper for managing configuration files.
- Logging: Implement structured logging using Zap.
- Error Handling: Add comprehensive error handling.
- Unit Testing: Add unit tests for commands.
- Dockerization: Package the CLI with Docker for easy deployment.
For any questions or support, please reach out via GitHub Issues.