Add todo and error command
parent
5c6ea5e9a4
commit
5f6ece5f42
@ -0,0 +1,51 @@
|
||||
use embed_nu::{
|
||||
nu_protocol::{engine::Command, Signature, SyntaxShape},
|
||||
CallExt,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ErrorCommand;
|
||||
|
||||
impl Command for ErrorCommand {
|
||||
fn name(&self) -> &str {
|
||||
"todo"
|
||||
}
|
||||
|
||||
fn signature(&self) -> embed_nu::nu_protocol::Signature {
|
||||
Signature::new("error")
|
||||
.rest("message", SyntaxShape::Any, "The error message")
|
||||
.category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into()))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Throws an error"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &embed_nu::nu_protocol::engine::EngineState,
|
||||
stack: &mut embed_nu::nu_protocol::engine::Stack,
|
||||
call: &embed_nu::nu_protocol::ast::Call,
|
||||
_input: embed_nu::PipelineData,
|
||||
) -> Result<embed_nu::PipelineData, embed_nu::nu_protocol::ShellError> {
|
||||
let args: Vec<String> = call.rest(engine_state, stack, 0)?;
|
||||
|
||||
if args.is_empty() {
|
||||
Err(embed_nu::nu_protocol::ShellError::GenericError(
|
||||
String::from("Error"),
|
||||
String::from("Error"),
|
||||
Some(call.span()),
|
||||
None,
|
||||
vec![],
|
||||
))
|
||||
} else {
|
||||
Err(embed_nu::nu_protocol::ShellError::GenericError(
|
||||
String::from("Error"),
|
||||
args.join(" "),
|
||||
Some(call.span()),
|
||||
None,
|
||||
vec![],
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
mod debug;
|
||||
mod error;
|
||||
mod info;
|
||||
mod run;
|
||||
mod todo;
|
||||
mod warn;
|
||||
mod with_cwd;
|
||||
pub use debug::*;
|
||||
pub use error::*;
|
||||
pub use info::*;
|
||||
pub use run::*;
|
||||
pub use todo::*;
|
||||
pub use warn::*;
|
||||
pub use with_cwd::*;
|
||||
|
@ -0,0 +1,51 @@
|
||||
use embed_nu::{
|
||||
nu_protocol::{engine::Command, Signature, SyntaxShape},
|
||||
CallExt,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TodoCommand;
|
||||
|
||||
impl Command for TodoCommand {
|
||||
fn name(&self) -> &str {
|
||||
"todo"
|
||||
}
|
||||
|
||||
fn signature(&self) -> embed_nu::nu_protocol::Signature {
|
||||
Signature::new("todo")
|
||||
.rest("todo", SyntaxShape::Any, "Hints on what is todo")
|
||||
.category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into()))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Aborts the program as this is not implemented yet"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &embed_nu::nu_protocol::engine::EngineState,
|
||||
stack: &mut embed_nu::nu_protocol::engine::Stack,
|
||||
call: &embed_nu::nu_protocol::ast::Call,
|
||||
_input: embed_nu::PipelineData,
|
||||
) -> Result<embed_nu::PipelineData, embed_nu::nu_protocol::ShellError> {
|
||||
let args: Vec<String> = call.rest(engine_state, stack, 0)?;
|
||||
|
||||
if args.is_empty() {
|
||||
Err(embed_nu::nu_protocol::ShellError::GenericError(
|
||||
String::from("TODO"),
|
||||
String::from("This is a TODO"),
|
||||
Some(call.span()),
|
||||
Some(String::from("Implement this functionality")),
|
||||
vec![],
|
||||
))
|
||||
} else {
|
||||
Err(embed_nu::nu_protocol::ShellError::GenericError(
|
||||
String::from("TODO"),
|
||||
format!("This is a TODO: {}", args.join(" ")),
|
||||
Some(call.span()),
|
||||
Some(String::from("Implement this functionality")),
|
||||
vec![],
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue