use super::format_arg;
use endbasic_core::*;
use std::borrow::Cow;
use std::cell::RefCell;
use std::rc::Rc;
pub(super) struct OutRequiredValueCommand {
metadata: Rc<CallableMetadata>,
output: Rc<RefCell<String>>,
}
impl OutRequiredValueCommand {
pub(super) fn new(output: Rc<RefCell<String>>) -> Rc<Self> {
Rc::from(Self {
metadata: CallableMetadataBuilder::new("OUT_REQUIRED_VALUE")
.with_syntax(&[(
&[SingularArgSyntax::RequiredValue(
RequiredValueSyntax {
name: Cow::Borrowed("arg"),
vtype: ExprType::Integer,
},
ArgSepSyntax::End,
)],
None,
)])
.test_build(),
output,
})
}
}
impl Callable for OutRequiredValueCommand {
fn metadata(&self) -> Rc<CallableMetadata> {
self.metadata.clone()
}
fn exec(&self, scope: Scope<'_>) -> CallResult<()> {
let mut output = self.output.borrow_mut();
output.push_str(&format_arg(&scope, 0, ExprType::Integer));
output.push('\n');
Ok(())
}
}