ClassNames
class_names
Class name definitions for the application.
This module defines the canonical set of supported character classes using a string-based enumeration. It also provides utilities for parsing user input (e.g., from CLI arguments) into validated enum values.
The enum values are lowercase strings to align with CLI input and external representations.
Example
>>> parse_class_name("cleric")
<ClassName.CLERIC: 'cleric'>
>>> parse_class_name("invalid")
Traceback (most recent call last):
...
ValueError: Invalid class name: invalid
ClassName
Bases: StrEnum
Enumeration of supported character classes.
This enum uses StrEnum so that each member behaves like a string, making
it convenient for CLI parsing, serialization, and comparison.
Values are automatically generated as lowercase strings matching the member names.
Members
- CLERIC: Cleric class
- FIGHTER: Fighter class
- MAGIC_USER: Magic-user class
- THIEF: Thief class
Source code in src/rpgleveler/core/class_names.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
parse_class_name(class_name)
Parse a string into a ClassName enum value.
This function is intended for use at system boundaries (e.g., CLI input), where user-provided strings must be validated and converted into strongly-typed enum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
The input string representing a class name. |
required |
Returns:
| Type | Description |
|---|---|
ClassName
|
A corresponding |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input does not match any valid class name. |
Example
>>> parse_class_name("fighter")
<ClassName.FIGHTER: 'fighter'>
Source code in src/rpgleveler/core/class_names.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |