Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ robotvibecoder = "robotvibecoder.main:main"
[tool.hatch.version]
source = "versioningit"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.envs.types]
extra-dependencies = ["mypy>=1.0.0"]
[tool.hatch.envs.types.scripts]
Expand Down
17 changes: 17 additions & 0 deletions src/robotvibecoder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from enum import Enum
import json
import sys
from typing import Union

from robotvibecoder.cli import print_err

Expand All @@ -24,6 +25,22 @@ class MechanismKind(str, Enum):
ELEVATOR = "Elevator"
FLYWHEEL = "Flywheel"

@staticmethod
def try_into(value: str) -> Union["MechanismKind", None]:
"""Try to parse a string into a MechanismKind.
Returns none if the string isn't a valid MechanismKind.

:param value: The string to convert
:type value: str
:return: A MechanismKind if value is a valid Mechanism Kind, otherwise none
:rtype: MechanismKind | None
"""
for kind in MechanismKind:
if value == kind:
return kind

return None


@dataclass
class MechanismConfig:
Expand Down
9 changes: 6 additions & 3 deletions src/robotvibecoder/subcommands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ def new_config_interactive() -> MechanismConfig:

print("Kind: Should be either 'Elevator', 'Arm', or 'Flywheel'")
kind: str = ""
while kind not in MechanismKind:
while MechanismKind.try_into(kind) is None:
kind = input("> ")
if kind not in MechanismKind:
if MechanismKind.try_into(kind) is None:
print("Please input either Elevator, Arm, or Flywheel.")
kind_enum: MechanismKind = MechanismKind[kind]
kind_try = MechanismKind.try_into(kind)
kind_enum: MechanismKind = (
kind_try if kind_try is not None else MechanismKind.ELEVATOR
)

print("CAN Bus: whatever the name of the mechanism's bus is (e.g. `canivore`)")
canbus: str = input("> ")
Expand Down