currency_converter_cli

Crates.iocurrency_converter_cli
lib.rscurrency_converter_cli
version1.0.0
sourcesrc
created_at2024-06-15 21:27:27.352515
updated_at2024-06-22 11:06:41.851367
descriptionA simple CLI tool to convert GBP to CNY using real-time exchange rates.
homepagehttps://github.com/xyf2002/currency_converter
repositoryhttps://github.com/xyf2002/currency_converter
max_upload_size
id1273135
size49,704
Alex Xia (xyf2002)

documentation

README

Currency Converter CLI

A simple CLI tool to convert currencies using real-time exchange rates.

Features

  • Converts between multiple currencies.
  • Supports forward and reverse currency conversion.
  • Fetches real-time exchange rates from an API.
  • Displays currency symbols in the output.
  • Lists available currencies.
  • Interactive menu for easy use.

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/currency_converter.git
    cd currency_converter
    
  2. Create a .env file in the project root directory and add your API key:

    echo "EXCHANGE_RATE_API_KEY=your_api_key_here" > .env
    
  3. Build the project:

    cargo build --release
    

Usage

Convert Currency

To convert an amount from one currency to another, run the following command:

./target/release/currency_converter convert --amount <AMOUNT> --from <SOURCE_CURRENCY> --to <TARGET_CURRENCY>

For example, to convert 100 GBP to CNY:

./target/release/currency_converter convert --amount 100 --from GBP --to CNY

Reverse Convert Currency

To reverse convert an amount to the source currency, run the following command:

./target/release/currency_converter reverse-convert --amount <AMOUNT> --from <SOURCE_CURRENCY> --to <TARGET_CURRENCY>

For example, to find out how much GBP is needed to get 100 CNY:

./target/release/currency_converter reverse-convert --amount 100 --from GBP --to CNY

List Available Currencies

To list all available currencies, run:

./target/release/currency_converter list-currencies

Interactive Menu

You can also run the tool in an interactive menu mode:

./target/release/currency_converter

In the interactive menu, you will have the following options:

=============================
  Currency Converter Menu:
=============================
  1. Convert currency
  2. Reverse convert currency
  3. List available currencies
  Q. Quit
=============================
Enter your choice:

Follow the prompts to perform the desired operation.

Example Output

=============================
100.00 GBP is 922.05 ¥ (Rate as of 2024-06-22 12:00:00 UTC)
=============================

or

=============================
100.00 ¥ is 10.84 GBP (Rate as of 2024-06-22 12:00:00 UTC)
=============================

API Key

This tool uses the ExchangeRate-API to fetch real-time exchange rates. You need to sign up for an API key and add it to the .env file in the project root.

License

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


Commit count: 15

cargo fmt