Coverage for / home / runner / work / bijux-cli / bijux-cli / src / bijux_cli / core / enums.py: 97%
59 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
1# SPDX-License-Identifier: Apache-2.0
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__}")
52class ColorMode(str, Enum):
53 """Specifies terminal color handling for CLI output."""
55 AUTO = "auto"
56 ALWAYS = "always"
57 NEVER = "never"
59 @classmethod
60 def _missing_(cls, value: object) -> ColorMode:
61 """Handle case-insensitive lookup of color modes."""
62 if isinstance(value, str): 62 ↛ 67line 62 didn't jump to line 67 because the condition on line 62 was always true
63 value_lower = value.lower()
64 for member in cls:
65 if member.value == value_lower:
66 return member
67 raise ValueError(f"{value} is not a valid {cls.__name__}")
70class LogLevel(str, Enum):
71 """Logging level names for structured logging."""
73 TRACE = "trace"
74 DEBUG = "debug"
75 INFO = "info"
76 WARNING = "warning"
77 ERROR = "error"
78 CRITICAL = "critical"
80 @classmethod
81 def _missing_(cls, value: object) -> LogLevel:
82 """Handle case-insensitive lookup of log levels."""
83 if isinstance(value, str): 83 ↛ 88line 83 didn't jump to line 88 because the condition on line 83 was always true
84 value_lower = value.lower()
85 for member in cls:
86 if member.value == value_lower:
87 return member
88 raise ValueError(f"{value} is not a valid {cls.__name__}")
91class ExecutionMode(str, Enum):
92 """Execution mode for the runtime kernel."""
94 CLI = "cli"
95 API = "api"
96 REPL = "repl"
99class ExitCode(int, Enum):
100 """Standardized exit codes for command execution."""
102 SUCCESS = 0
103 ERROR = 1
104 USAGE = 2
105 ASCII = 3
106 ABORTED = 130
109class ErrorType(str, Enum):
110 """High-level error categories for exit behavior."""
112 USAGE = "usage"
113 ASCII = "ascii"
114 USER_INPUT = "user_input"
115 CONFIG = "config"
116 PLUGIN = "plugin"
117 INTERNAL = "internal"
118 ABORTED = "aborted"
121__all__ = [
122 "ColorMode",
123 "OutputFormat",
124 "LogLevel",
125 "ExecutionMode",
126 "ExitCode",
127 "ErrorType",
128]