|
|
|
@ -66,29 +66,71 @@ class FeatureOptionHolder(InterpreterObject, ObjectHolder[coredata.UserFeatureOp |
|
|
|
|
def __init__(self, env: 'Environment', name: str, option: coredata.UserFeatureOption): |
|
|
|
|
InterpreterObject.__init__(self) |
|
|
|
|
ObjectHolder.__init__(self, option) |
|
|
|
|
if option.is_auto(): |
|
|
|
|
if option and option.is_auto(): |
|
|
|
|
# TODO: we need to case here because options is not a TypedDict |
|
|
|
|
self.held_object = T.cast(coredata.UserFeatureOption, env.coredata.options[OptionKey('auto_features')]) |
|
|
|
|
self.name = name |
|
|
|
|
self.methods.update({'enabled': self.enabled_method, |
|
|
|
|
'disabled': self.disabled_method, |
|
|
|
|
'allowed': self.allowed_method, |
|
|
|
|
'auto': self.auto_method, |
|
|
|
|
'require': self.require_method, |
|
|
|
|
'disable_auto_if': self.disable_auto_if_method, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def value(self): |
|
|
|
|
return 'disabled' if not self.held_object else self.held_object.value |
|
|
|
|
|
|
|
|
|
def as_disabled(self): |
|
|
|
|
return FeatureOptionHolder(None, self.name, None) |
|
|
|
|
|
|
|
|
|
@noPosargs |
|
|
|
|
@permittedKwargs({}) |
|
|
|
|
def enabled_method(self, args, kwargs): |
|
|
|
|
return self.held_object.is_enabled() |
|
|
|
|
return self.value == 'enabled' |
|
|
|
|
|
|
|
|
|
@noPosargs |
|
|
|
|
@permittedKwargs({}) |
|
|
|
|
def disabled_method(self, args, kwargs): |
|
|
|
|
return self.held_object.is_disabled() |
|
|
|
|
return self.value == 'disabled' |
|
|
|
|
|
|
|
|
|
@noPosargs |
|
|
|
|
@permittedKwargs({}) |
|
|
|
|
def allowed_method(self, args, kwargs): |
|
|
|
|
return not self.value == 'disabled' |
|
|
|
|
|
|
|
|
|
@noPosargs |
|
|
|
|
@permittedKwargs({}) |
|
|
|
|
def auto_method(self, args, kwargs): |
|
|
|
|
return self.held_object.is_auto() |
|
|
|
|
return self.value == 'auto' |
|
|
|
|
|
|
|
|
|
@permittedKwargs({'error_message'}) |
|
|
|
|
def require_method(self, args, kwargs): |
|
|
|
|
if len(args) != 1: |
|
|
|
|
raise InvalidArguments('Expected 1 argument, got %d.' % (len(args), )) |
|
|
|
|
if not isinstance(args[0], bool): |
|
|
|
|
raise InvalidArguments('boolean argument expected.') |
|
|
|
|
error_message = kwargs.pop('error_message', '') |
|
|
|
|
if error_message and not isinstance(error_message, str): |
|
|
|
|
raise InterpreterException("Error message must be a string.") |
|
|
|
|
if args[0]: |
|
|
|
|
return self |
|
|
|
|
|
|
|
|
|
if self.value == 'enabled': |
|
|
|
|
prefix = 'Feature {} cannot be enabled'.format(self.name) |
|
|
|
|
prefix = prefix + ': ' if error_message else '' |
|
|
|
|
raise InterpreterException(prefix + error_message) |
|
|
|
|
return self.as_disabled() |
|
|
|
|
|
|
|
|
|
@permittedKwargs({}) |
|
|
|
|
def disable_auto_if_method(self, args, kwargs): |
|
|
|
|
if len(args) != 1: |
|
|
|
|
raise InvalidArguments('Expected 1 argument, got %d.' % (len(args), )) |
|
|
|
|
if not isinstance(args[0], bool): |
|
|
|
|
raise InvalidArguments('boolean argument expected.') |
|
|
|
|
return self if self.value != 'auto' or not args[0] else self.as_disabled() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RunProcess(InterpreterObject): |
|
|
|
|
|
|
|
|
|