Start implementing scenario run().

Add different template string char.
This commit is contained in:
Chris Daßler 2024-08-07 22:03:13 +00:00
parent 54adfe5095
commit c73ce95fd9
2 changed files with 38 additions and 21 deletions

View File

@ -1,5 +1,7 @@
use nu_plugin::{EngineInterface, EvaluatedCall, SimplePluginCommand};
use nu_protocol::{record, Category, Example, LabeledError, Signature, Value};
use nu_protocol::{
record, Category, Example, IntoSpanned, LabeledError, PipelineData, Signature, Spanned, Value,
};
use crate::OncePlugin;
@ -17,7 +19,7 @@ impl SimplePluginCommand for Scenario {
}
fn extra_usage(&self) -> &str {
r"This command shows all available scenarios. To manage these scenarios use the sub commands, e.g.
r"This command shows all available scenarios. To manage these scenarios use the sub commands, e.g.
> once scenario.deploy"
}
@ -44,27 +46,42 @@ impl SimplePluginCommand for Scenario {
fn run(
&self,
_plugin: &OncePlugin,
_engine: &EngineInterface,
engine: &EngineInterface,
call: &EvaluatedCall,
_input: &Value,
) -> Result<Value, LabeledError> {
let head = call.head;
let list = vec![
Value::record(
record! {
"name" => Value::test_string("dev"),
"filename" => Value::test_string("dev.scenario.env")
},
head,
),
Value::record(
record! {
"name" => Value::test_string("certbot"),
"filename" => Value::test_string("certbot.scenario.env")
},
head,
),
];
const SCENARIO_SOURCE_PATH: &str = "/workspaces/Once.2023/Scenarios";
let name: Spanned<String> = Spanned {
span: head,
item: "glob".to_owned(),
};
let decl_id = engine.find_decl(&name.item)?.ok_or_else(|| {
LabeledError::new(format!("Can't find `{}`", name.item))
.with_label("not in scope", name.span)
})?;
let mut new_call = EvaluatedCall::new(call.head);
//new_call.add_flag("l".into_spanned(head));
new_call.add_positional(Value::string(
format!("{}/**/*.{{scenario,env}}", SCENARIO_SOURCE_PATH),
head,
));
// TODO: Filter out localhost is not working yet
new_call.add_named(
"exclude".into_spanned(head),
Value::string("[**/localhost/*]", head),
);
let result: PipelineData =
engine.call_decl(decl_id, new_call, PipelineData::Empty, true, false)?;
let mut list = vec![];
for res in result.into_iter() {
list.push(res);
}
Ok(Value::list(list, head))
}
}

View File

@ -17,7 +17,7 @@ impl SimplePluginCommand for ScenarioDeploy {
}
fn extra_usage(&self) -> &str {
r" Lifecycle actions:
r#" Lifecycle actions:
init - init remote scenario dir
up - Create and start scenario
stop - Stop scenario
@ -27,7 +27,7 @@ impl SimplePluginCommand for ScenarioDeploy {
Service actions:
test - Test the running scenario
updateconfig - update local scenario config"
updateconfig - update local scenario config"#
}
fn signature(&self) -> Signature {