Skip to main content

Building F1CLI: A Fun Dive into CLI Development ๐ŸŽ๏ธ ๐Ÿ

00:02:12:59

You know those moments when you think, "This feature isn't necessary, but it'd be so cool to build it?" That's exactly how I felt when creating F1CLIโ€”a command-line interface for Formula 1 data. Itโ€™s a small project, but one that taught me a lot about scripting, APIs, and user experience in the terminal.

๐Ÿ›  The Idea

As a Formula 1 fan and a developer, I wanted quick access to race results without constantly visiting websites. A CLI felt like a natural fitโ€”lightweight, fast, and geeky in the best way possible. So, I got to work.

๐Ÿงฉ Key Features

Hereโ€™s what F1CLI does:

  • Fetch Latest Race Results: Display race standings in a simple table.
  • Driver & Team Stats: Drill down into performance details.
  • Standings: Get the big picture with driver and constructor rankings.

You run it like this:

bash
./f1cli.sh --standings
./f1cli.sh --driver verstappen

๐Ÿค“ Tech Stack

I kept it simple with Bash, focusing on minimal dependencies and ease of execution. The tool pulls data from the Ergast Developer APIโ€”a fantastic resource for F1 statistics.

Snippet: Fetching Data with curl

To make API calls, I used curl:

bash
curl -s "http://ergast.com/api/f1/current/last/results" | jq '.'

The jq tool helped parse JSON responses, turning raw data into actionable results.

๐Ÿค” Challenges and Solutions

Parsing JSON in Bash

Bash isn't exactly JSON-friendly. Initially, I tried manual parsing, but that quickly became messy. Enter jq, which simplified everything.

bash
driver_name=$(echo $json_data | jq -r '.Driver.givenName')

๐Ÿงช Testing the CLI

Testing a CLI tool involves running multiple scenarios manually. Hereโ€™s an example test case I used:

  1. Scenario: Fetch standings

    bash
    ./f1cli.sh --standings
    

    Expected Output: A neatly formatted standings table.

  2. Scenario: Fetch data for a specific driver

    bash
    ./f1cli.sh --driver leclerc
    

    Expected Output: Stats for Charles Leclerc.

๐Ÿš€ Lessons Learned

  • Keep It Simple: For CLI tools, simplicity beats overengineering every time.
  • APIs are Your Best Friend: The Ergast API made this project feasible.
  • Community Tools: Tools like jq can save hours of custom coding.

What's Next? ๐ŸŽ

While F1CLI is functional, thereโ€™s always room for growth:

  1. Adding more detailed race insights.
  2. Packaging it as a distributable binary.
  3. Supporting other sports (just in case the offseason gets boring).

Check out the GitHub repository here.

Final Thoughts

F1CLI is a small project, but itโ€™s a big reminder of why I love coding. Sometimes, the most "useless" tools turn out to be the most rewarding. Whether you're an F1 fan or just curious about Bash scripting, I hope this inspires you to build something fun.