use super::format_vararg;
use endbasic_core::*;
use std::borrow::Cow;
use std::cell::RefCell;
use std::rc::Rc;
pub(super) struct OutAnyValueCommand {
metadata: Rc<CallableMetadata>,
output: Rc<RefCell<String>>,
}
impl OutAnyValueCommand {
pub(super) fn new(output: Rc<RefCell<String>>) -> Rc<Self> {
Rc::from(Self {
metadata: CallableMetadataBuilder::new("OUT_ANY_VALUE")
.with_syntax(&[(
&[SingularArgSyntax::AnyValue(
AnyValueSyntax { name: Cow::Borrowed("arg"), allow_missing: false },
ArgSepSyntax::End,
)],
None,
)])
.test_build(),
output,
})
}
}
impl Callable for OutAnyValueCommand {
fn metadata(&self) -> Rc<CallableMetadata> {
self.metadata.clone()
}
fn exec(&self, scope: Scope<'_>) -> CallResult<()> {
let (formatted, _present, sep) = format_vararg(&scope, 0);
assert_eq!(ArgSep::End, sep, "Command only expects one argument");
let mut output = self.output.borrow_mut();
output.push_str(&formatted);
output.push('\n');
Ok(())
}
}