Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/core/enums.py: 100%
14 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
1# SPDX-License-Identifier: MIT
2# Copyright © 2025 Bijan Mousavi
4"""Defines the output format enumeration for the Bijux CLI.
6This module provides the `OutputFormat` enum, which represents the
7supported structured output formats (JSON and YAML). Using an enum ensures
8type safety and provides a single source of truth for format names. It also
9includes a mechanism for case-insensitive matching.
10"""
12from __future__ import annotations
14from enum import Enum
17class OutputFormat(str, Enum):
18 """Specifies the supported structured output formats for CLI responses.
20 This enum supports case-insensitive matching, so `OutputFormat("JSON")` and
21 `OutputFormat("yaml")` are both valid.
22 """
24 JSON = "json"
25 YAML = "yaml"
27 @classmethod
28 def _missing_(cls, value: object) -> OutputFormat:
29 """Handles case-insensitive lookup of enum members.
31 This special method is called by the `Enum` metaclass when a value is
32 not found. This implementation retries the lookup in lowercase.
34 Args:
35 value: The value being looked up.
37 Returns:
38 OutputFormat: The matching enum member.
40 Raises:
41 ValueError: If no matching member is found after converting the
42 input value to lowercase.
43 """
44 if isinstance(value, str):
45 value_lower = value.lower()
46 for member in cls:
47 if member.value == value_lower:
48 return member
49 raise ValueError(f"{value} is not a valid {cls.__name__}")
52__all__ = ["OutputFormat"]