MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ConfigOption

Class ConfigOption

tools/ng/config.py:24–59  ·  view source on GitHub ↗

Configuration option with metadata.

Source from the content-addressed store, hash-verified

22
23@dataclass
24class ConfigOption:
25 """Configuration option with metadata."""
26 name: str
27 value: Any
28 type: ConfigType
29 line_number: int = 0
30 comment: str = ""
31
32 def as_bool(self) -> bool:
33 """Get value as boolean."""
34 if self.type == ConfigType.BOOLEAN:
35 return bool(self.value)
36 elif self.type == ConfigType.INTEGER:
37 return self.value != 0
38 elif self.type == ConfigType.STRING:
39 return bool(self.value)
40 return False
41
42 def as_int(self) -> int:
43 """Get value as integer."""
44 if self.type == ConfigType.INTEGER:
45 return self.value
46 elif self.type == ConfigType.BOOLEAN:
47 return 1 if self.value else 0
48 elif self.type == ConfigType.STRING:
49 try:
50 return int(self.value)
51 except ValueError:
52 return 0
53 return 0
54
55 def as_str(self) -> str:
56 """Get value as string."""
57 if self.type == ConfigType.STRING:
58 return self.value
59 return str(self.value)
60
61
62class ConfigParser:

Callers 1

_parse_lineMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected