use nu_plugin::{EngineInterface, EvaluatedCall, SimplePluginCommand};
use nu_protocol::{Example, LabeledError, Signature, SyntaxShape, Value};
use crate::plugin::JevPlugin;
use super::{build_noul, question_to_nu};
pub(crate) struct JevQuestionNoul;
impl SimplePluginCommand for JevQuestionNoul {
type Plugin = JevPlugin;
fn name(&self) -> &str {
"jev question noul"
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.required(
"instructions",
SyntaxShape::Any,
"The condition or decision instructions",
)
.named(
"yes",
SyntaxShape::Any,
"Description of the true case",
None,
)
.named(
"no",
SyntaxShape::Any,
"Description of the false case",
None,
)
}
fn description(&self) -> &str {
"Build a Noul probability question as a Nu record"
}
fn extra_description(&self) -> &str {
"No network request is made. Missing --yes/--no fields are omitted; an explicitly supplied null remains null."
}
fn examples(&self) -> Vec<Example<'_>> {
vec![Example {
example: "jev question noul 'Is this spam?' --yes 'Unsolicited message'",
description: "Create a Noul question with only a true-case description",
result: None,
}]
}
fn run(
&self,
_plugin: &JevPlugin,
_engine: &EngineInterface,
call: &EvaluatedCall,
_input: &Value,
) -> Result<Value, LabeledError> {
let instructions: Value = call.req(0).map_err(LabeledError::from)?;
let yes = call.get_flag_value("yes");
let no = call.get_flag_value("no");
question_to_nu(
build_noul(&instructions, yes.as_ref(), no.as_ref())?,
call.head,
)
}
}