This CLI application is written using the Cobra library to provide a more engaging and professional command-line experience. As someone experienced in Go and many other programming languages, I find basic input/output with fmt.Scan
and fmt.Println
to be repetitive and not interesting. To make this project more enjoyable and educational, I have used Cobra for command parsing and help messages, and used some design patterns such as Singleton for state management.
A command-line tool to calculate profit, Earnings Before Tax (EBT), and profit ratios based on your revenue, tax rate, and expenses. Built with Go and Cobra.
- Calculate net profit after tax and expenses
- Calculate Earnings Before Tax (EBT)
- Compute profit ratios
- Easy-to-use command-line interface
Clone the repository and build the binary:
git clone https://github.com/mr3iscuit/golang-exercise1-profit-calculator.git
cd golang-exercise1-profit-calculator
go build -o profit-calc
Run the CLI with the desired command and flags:
./profit-calc [command] [flags]
--revenue, -r
Total revenue (income) amount (required)--tax-rate, -t
Tax rate as a percentage (e.g., 15 for 15%) (required)--expenses, -e
Total expenses amount (required)
./profit-calc profit --revenue 10000 --tax-rate 15 --expenses 3000
./profit-calc ebt --revenue 10000 --tax-rate 15 --expenses 3000
./profit-calc ratio --revenue 10000 --tax-rate 15 --expenses 3000
Earnings Before Tax: 5950.000000
For more information on commands and flags:
./profit-calc --help
./profit-calc profit --help
./profit-calc ebt --help
./profit-calc ratio --help
MIT