[GH-ISSUE #36] Improve CLI: Add --speed flag, error handling, and fix default year #7

Closed
opened 2026-05-07 00:17:31 +02:00 by BreizhHardware · 2 comments

Originally created by @MohitBaghel24 on GitHub (Dec 12, 2025).
Original GitHub issue: https://github.com/IAmTomShaw/f1-race-replay/issues/36

GitHub Issues for F1 Race Replay

Issue #1: Missing Command-Line Argument for Playback Speed

Title

Feature: Add command-line argument for playback speed control

Labels

enhancement, usability

Description

The playback_speed parameter exists in the main() function but cannot be controlled via command-line arguments. Users can adjust --year, --round, and session type, but playback speed is hardcoded to 1.

Location

File: main.py
Lines: 82, 87

Current Behavior

playback_speed = 1  # Hardcoded, no CLI option

Expected Behavior

Users should be able to control playback speed via a command-line argument:

python main.py --speed 2.0
python main.py --year 2024 --round 10 --speed 0.5

Suggested Implementation

if "--speed" in sys.argv:
    speed_index = sys.argv.index("--speed") + 1
    playback_speed = float(sys.argv[speed_index])
else:
    playback_speed = 1.0  # Default speed

Impact

  • Improved user experience
  • Better control over replay visualization
  • Consistency with other command-line arguments

Issue #2: No Error Handling for Invalid Command-Line Arguments

Title

Bug: Missing error handling for invalid CLI arguments causes crashes

Labels

bug, crash, error-handling

Description

The script crashes with IndexError or ValueError when users provide invalid command-line arguments for --year or --round. There's no validation or error handling.

Location

File: main.py
Lines: 71-72, 77-78

Current Behavior

if "--year" in sys.argv:
    year_index = sys.argv.index("--year") + 1
    year = int(sys.argv[year_index])  # Can crash here

Crash Scenarios

python main.py --year          # IndexError: list index out of range
python main.py --year abc      # ValueError: invalid literal for int()
python main.py --round         # IndexError: list index out of range
python main.py --round xyz     # ValueError: invalid literal for int()

Expected Behavior

The script should:

  1. Validate that arguments have values
  2. Validate that values are valid integers
  3. Show helpful error messages
  4. Exit gracefully

Suggested Implementation

try:
    if "--year" in sys.argv:
        year_index = sys.argv.index("--year") + 1
        if year_index >= len(sys.argv):
            raise ValueError("--year requires a value")
        year = int(sys.argv[year_index])
    else:
        year = 2024  # Default year
except (ValueError, IndexError) as e:
    print(f"Error: Invalid --year argument. {e}")
    sys.exit(1)

Impact

Severity: High

  • Application crashes without helpful feedback
  • Poor user experience
  • Makes CLI unusable for newcomers

Issue #3: Incorrect Code Indentation

Title

Bug: Incorrect indentation for session type comment

Labels

bug, code-quality

Description

The comment # Session type selection on line 84 is incorrectly indented at module level instead of being inside the if __name__ == "__main__": block.

Location

File: main.py
Line: 84

Current Behavior

  playback_speed = 1

# Session type selection  # ❌ Wrong indentation
  session_type = 'SQ' if ...

Expected Behavior

  playback_speed = 1

  # Session type selection  # ✅ Correct indentation
  session_type = 'SQ' if ...

Impact

Severity: Low

  • Affects code readability
  • Violates PEP 8 style guidelines
  • May confuse developers

Issue #4: Default Year May Cause Runtime Errors

Title

Bug: Default year 2025 may not have available data

Labels

bug, data, configuration

Description

The default year is set to 2025 (line 74), but F1 session data for 2025 may not be available depending on when the script is run. This could cause runtime errors when attempting to load session data.

Location

File: main.py
Line: 74

Current Behavior

else:
    year = 2025  # Default year - may not have data yet

Potential Error

Error: No data available for 2025 Round 12

Expected Behavior

Use a more conservative default year that's guaranteed to have data, or detect the current F1 season dynamically.

Suggested Solutions

Option 1: Use previous year

from datetime import datetime
current_year = datetime.now().year
year = current_year - 1  # Use previous completed season

Option 2: Use specific known year

year = 2024  # Most recent completed season

Option 3: Check data availability

year = 2024  # Safe default
# Add validation in load_session to check data availability

Impact

Severity: Medium

  • Script may fail on first run without arguments
  • Confusing error messages for new users
  • Reduces out-of-box usability

---****

Originally created by @MohitBaghel24 on GitHub (Dec 12, 2025). Original GitHub issue: https://github.com/IAmTomShaw/f1-race-replay/issues/36 # GitHub Issues for F1 Race Replay ## Issue #1: Missing Command-Line Argument for Playback Speed ### Title **Feature: Add command-line argument for playback speed control** ### Labels `enhancement`, `usability` ### Description The `playback_speed` parameter exists in the `main()` function but cannot be controlled via command-line arguments. Users can adjust `--year`, `--round`, and session type, but playback speed is hardcoded to `1`. ### Location **File:** `main.py` **Lines:** 82, 87 ### Current Behavior ```python playback_speed = 1 # Hardcoded, no CLI option ``` ### Expected Behavior Users should be able to control playback speed via a command-line argument: ```bash python main.py --speed 2.0 python main.py --year 2024 --round 10 --speed 0.5 ``` ### Suggested Implementation ```python if "--speed" in sys.argv: speed_index = sys.argv.index("--speed") + 1 playback_speed = float(sys.argv[speed_index]) else: playback_speed = 1.0 # Default speed ``` ### Impact - Improved user experience - Better control over replay visualization - Consistency with other command-line arguments --- ## Issue #2: No Error Handling for Invalid Command-Line Arguments ### Title **Bug: Missing error handling for invalid CLI arguments causes crashes** ### Labels `bug`, `crash`, `error-handling` ### Description The script crashes with `IndexError` or `ValueError` when users provide invalid command-line arguments for `--year` or `--round`. There's no validation or error handling. ### Location **File:** `main.py` **Lines:** 71-72, 77-78 ### Current Behavior ```python if "--year" in sys.argv: year_index = sys.argv.index("--year") + 1 year = int(sys.argv[year_index]) # Can crash here ``` ### Crash Scenarios ```bash python main.py --year # IndexError: list index out of range python main.py --year abc # ValueError: invalid literal for int() python main.py --round # IndexError: list index out of range python main.py --round xyz # ValueError: invalid literal for int() ``` ### Expected Behavior The script should: 1. Validate that arguments have values 2. Validate that values are valid integers 3. Show helpful error messages 4. Exit gracefully ### Suggested Implementation ```python try: if "--year" in sys.argv: year_index = sys.argv.index("--year") + 1 if year_index >= len(sys.argv): raise ValueError("--year requires a value") year = int(sys.argv[year_index]) else: year = 2024 # Default year except (ValueError, IndexError) as e: print(f"Error: Invalid --year argument. {e}") sys.exit(1) ``` ### Impact **Severity:** High - Application crashes without helpful feedback - Poor user experience - Makes CLI unusable for newcomers --- ## Issue #3: Incorrect Code Indentation ### Title **Bug: Incorrect indentation for session type comment** ### Labels `bug`, `code-quality` ### Description The comment `# Session type selection` on line 84 is incorrectly indented at module level instead of being inside the `if __name__ == "__main__":` block. ### Location **File:** `main.py` **Line:** 84 ### Current Behavior ```python playback_speed = 1 # Session type selection # ❌ Wrong indentation session_type = 'SQ' if ... ``` ### Expected Behavior ```python playback_speed = 1 # Session type selection # ✅ Correct indentation session_type = 'SQ' if ... ``` ### Impact **Severity:** Low - Affects code readability - Violates PEP 8 style guidelines - May confuse developers --- ## Issue #4: Default Year May Cause Runtime Errors ### Title **Bug: Default year 2025 may not have available data** ### Labels `bug`, `data`, `configuration` ### Description The default year is set to `2025` (line 74), but F1 session data for 2025 may not be available depending on when the script is run. This could cause runtime errors when attempting to load session data. ### Location **File:** `main.py` **Line:** 74 ### Current Behavior ```python else: year = 2025 # Default year - may not have data yet ``` ### Potential Error ``` Error: No data available for 2025 Round 12 ``` ### Expected Behavior Use a more conservative default year that's guaranteed to have data, or detect the current F1 season dynamically. ### Suggested Solutions **Option 1: Use previous year** ```python from datetime import datetime current_year = datetime.now().year year = current_year - 1 # Use previous completed season ``` **Option 2: Use specific known year** ```python year = 2024 # Most recent completed season ``` **Option 3: Check data availability** ```python year = 2024 # Safe default # Add validation in load_session to check data availability ``` ### Impact **Severity:** Medium - Script may fail on first run without arguments - Confusing error messages for new users - Reduces out-of-box usability ---****
Author
Owner

@MohitBaghel24 commented on GitHub (Dec 12, 2025):

Fix: Add error handling, --speed flag, and improve CLI robustness

  • Add --speed command-line argument for playback speed control
  • Implement comprehensive error handling for invalid CLI arguments
  • Fix incorrect indentation for session type comment
  • Change default year from 2025 to 2024 for better data availability
  • Add helpful usage message on error
  • Validate argument values before parsing

Fixes hardcoded playback speed parameter and prevents application crashes
from invalid command-line inputs.

<!-- gh-comment-id:3648236456 --> @MohitBaghel24 commented on GitHub (Dec 12, 2025): Fix: Add error handling, --speed flag, and improve CLI robustness - Add --speed command-line argument for playback speed control - Implement comprehensive error handling for invalid CLI arguments - Fix incorrect indentation for session type comment - Change default year from 2025 to 2024 for better data availability - Add helpful usage message on error - Validate argument values before parsing Fixes hardcoded playback speed parameter and prevents application crashes from invalid command-line inputs.
Author
Owner

@IAmTomShaw commented on GitHub (Jan 9, 2026):

Thanks for raising this issue! I

<!-- gh-comment-id:3729962407 --> @IAmTomShaw commented on GitHub (Jan 9, 2026): Thanks for raising this issue! I
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/f1-race-replay#7
No description provided.