diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-07-26 15:30:14 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-07-29 10:42:02 +0100 |
commit | 0f074dd37524047cb53214be5c0f10436d3abb1d (patch) | |
tree | ebe315fcb23739a7b43bc6747f5d5753813017ee /src/buildstream/node.pxd | |
parent | 0dacf84b3655fbe1e4da8f4a2f56a86aef9d89e4 (diff) | |
download | buildstream-0f074dd37524047cb53214be5c0f10436d3abb1d.tar.gz |
node: Add 'as_enum' on ScalarNode and 'get_enum' helper on MappingNode
This adds a method to ensure that a value is from a set of valid values
and raises an error message accordingly.
- Define Enum types for each of the relevant cases
- Adapt call places that were doing such things manually
Diffstat (limited to 'src/buildstream/node.pxd')
-rw-r--r-- | src/buildstream/node.pxd | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/buildstream/node.pxd b/src/buildstream/node.pxd index 18520146d..02e95d06f 100644 --- a/src/buildstream/node.pxd +++ b/src/buildstream/node.pxd @@ -46,6 +46,7 @@ cdef class MappingNode(Node): # Public Methods cpdef bint get_bool(self, str key, default=*) except * + cpdef object get_enum(self, str key, object constraint, object default=*) cpdef int get_int(self, str key, default=*) except * cpdef MappingNode get_mapping(self, str key, default=*) cpdef Node get_node(self, str key, list allowed_types=*, bint allow_none=*) @@ -78,6 +79,7 @@ cdef class ScalarNode(Node): # Public Methods cpdef bint as_bool(self) except * + cpdef object as_enum(self, object constraint) cpdef int as_int(self) except * cpdef str as_str(self) cpdef bint is_none(self) |