Compare commits

..

6 Commits

@ -1,6 +1,6 @@
[package] [package]
name = "embed-nu" name = "embed-nu"
version = "0.3.5" version = "0.5.1"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
repository = "https://github.com/Trivernis/embed-nu" repository = "https://github.com/Trivernis/embed-nu"
@ -10,10 +10,11 @@ authors = ["trivernis <trivernis@proton.me>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
nu-command = "0.71.0" miette = "5.5.0"
nu-engine = "0.71.0" nu-command = "0.75.0"
nu-parser = "0.71.0" nu-engine = "0.75.0"
nu-protocol = "0.71.0" nu-parser = "0.75.0"
paste = "1.0.9" nu-protocol = "0.75.0"
paste = "1.0.11"
rusty-value = { version = "0.6.0", features = ["derive"] } rusty-value = { version = "0.6.0", features = ["derive"] }
thiserror = "1.0.37" thiserror = "1.0.38"

@ -16,7 +16,9 @@ pub fn bind_core_commands(engine_state: &mut EngineState) -> CrateResult<()> {
engine_state, engine_state,
Alias, Alias,
Ast, Ast,
Break,
Commandline, Commandline,
Continue,
Debug, Debug,
Def, Def,
DefEnv, DefEnv,
@ -33,6 +35,7 @@ pub fn bind_core_commands(engine_state: &mut EngineState) -> CrateResult<()> {
Extern, Extern,
For, For,
Help, Help,
HelpOperators,
Hide, Hide,
HideEnv, HideEnv,
If, If,
@ -45,8 +48,12 @@ pub fn bind_core_commands(engine_state: &mut EngineState) -> CrateResult<()> {
Let, Let,
Metadata, Metadata,
Module, Module,
Mut,
Return,
Try,
Use, Use,
Version, Version,
While,
) )
} }
@ -117,8 +124,7 @@ pub fn bind_filter_commands(engine_state: &mut EngineState) -> CrateResult<()> {
Where, Where,
Window, Window,
Wrap, Wrap,
Zip, Zip, }
}
} }
pub fn bind_misc_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_misc_commands(engine_state: &mut EngineState) -> CrateResult<()> {
@ -151,13 +157,13 @@ pub fn bind_system_commands(engine_state: &mut EngineState) -> CrateResult<()> {
NuCheck, NuCheck,
Sys, Sys,
Ps, Ps,
Which,
} }
} }
pub fn bind_string_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_string_commands(engine_state: &mut EngineState) -> CrateResult<()> {
bind_commands! { bind_commands! {
engine_state, engine_state,
BuildString,
Char, Char,
Decode, Decode,
Encode, Encode,
@ -196,7 +202,7 @@ pub fn bind_string_commands(engine_state: &mut EngineState) -> CrateResult<()> {
StrSubstring, StrSubstring,
StrTrim, StrTrim,
StrTitleCase, StrTitleCase,
StrUpcase StrUpcase,
} }
} }
@ -324,12 +330,10 @@ pub fn bind_format_commands(engine_state: &mut EngineState) -> CrateResult<()> {
ToText, ToText,
ToToml, ToToml,
ToTsv, ToTsv,
ToCsv,
Touch, Touch,
Use, Use,
Upsert, Upsert,
Where, Where,
ToUrl,
ToXml, ToXml,
ToYaml, ToYaml,
} }
@ -355,6 +359,7 @@ pub fn bind_conversion_commands(engine_state: &mut EngineState) -> CrateResult<(
IntoDuration, IntoDuration,
IntoFilesize, IntoFilesize,
IntoInt, IntoInt,
IntoRecord,
IntoString, IntoString,
} }
} }
@ -380,7 +385,6 @@ pub fn bind_math_commands(engine_state: &mut EngineState) -> CrateResult<()> {
MathAbs, MathAbs,
MathAvg, MathAvg,
MathCeil, MathCeil,
MathEval,
MathFloor, MathFloor,
MathMax, MathMax,
MathMedian, MathMedian,
@ -398,13 +402,8 @@ pub fn bind_math_commands(engine_state: &mut EngineState) -> CrateResult<()> {
pub fn bind_network_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_network_commands(engine_state: &mut EngineState) -> CrateResult<()> {
bind_commands! { bind_commands! {
engine_state, engine_state,
Fetch,
Post,
Url, Url,
UrlHost, UrlParse,
UrlPath,
UrlQuery,
UrlScheme,
Port, Port,
} }
} }

@ -93,6 +93,7 @@ impl ContextBuilder {
name.to_string().into_bytes(), name.to_string().into_bytes(),
Span::empty(), Span::empty(),
nu_protocol::Type::Any, nu_protocol::Type::Any,
false,
); );
self.stack.add_var(var_id, value.into_value()); self.stack.add_var(var_id, value.into_value());
let delta = working_set.render(); let delta = working_set.render();

@ -99,6 +99,7 @@ impl Context {
arguments: args, arguments: args,
redirect_stdout: true, redirect_stdout: true,
redirect_stderr: true, redirect_stderr: true,
parser_info: Vec::new(),
}; };
let data = nu_engine::eval_call( let data = nu_engine::eval_call(

@ -1,3 +1,4 @@
use miette::Diagnostic;
use nu_parser::ParseError; use nu_parser::ParseError;
use nu_protocol::ShellError; use nu_protocol::ShellError;
use thiserror::Error; use thiserror::Error;
@ -15,3 +16,71 @@ pub enum CrateError {
#[error("Could not find the function {0}")] #[error("Could not find the function {0}")]
FunctionNotFound(String), FunctionNotFound(String),
} }
impl Diagnostic for CrateError {
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.code(),
CrateError::NuParseError(n) => n.code(),
Self::FunctionNotFound(_) => Some(Box::new("embed_nu::fn_not_found")),
}
}
fn severity(&self) -> Option<miette::Severity> {
match self {
CrateError::NuShellError(n) => n.severity(),
CrateError::NuParseError(n) => n.severity(),
_ => None,
}
}
fn help<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.help(),
CrateError::NuParseError(n) => n.help(),
CrateError::FunctionNotFound(_) => Some(Box::new(
"Make sure the function you want to execute is defined at this point.",
)),
}
}
fn url<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.url(),
CrateError::NuParseError(n) => n.url(),
_ => None,
}
}
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
match self {
CrateError::NuShellError(n) => n.source_code(),
CrateError::NuParseError(n) => n.source_code(),
_ => None,
}
}
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
match self {
CrateError::NuShellError(n) => n.labels(),
CrateError::NuParseError(n) => n.labels(),
_ => None,
}
}
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
match self {
CrateError::NuShellError(n) => n.related(),
CrateError::NuParseError(n) => n.related(),
_ => None,
}
}
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
match self {
CrateError::NuShellError(n) => n.diagnostic_source(),
CrateError::NuParseError(n) => n.diagnostic_source(),
_ => None,
}
}
}

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Block, ast::Block,
engine::{EngineState, StateWorkingSet}, engine::{EngineState, StateWorkingSet},
PipelineData, Span, Span,
}; };
use crate::error::{CrateError, CrateResult}; use crate::error::{CrateError, CrateResult};
@ -17,13 +17,6 @@ impl NewEmpty for Span {
} }
} }
impl NewEmpty for PipelineData {
#[inline]
fn empty() -> Self {
Self::new(Span::empty())
}
}
pub fn parse_nu_script(engine_state: &mut EngineState, contents: String) -> CrateResult<Block> { pub fn parse_nu_script(engine_state: &mut EngineState, contents: String) -> CrateResult<Block> {
let mut working_set = StateWorkingSet::new(&engine_state); let mut working_set = StateWorkingSet::new(&engine_state);
let (block, err) = nu_parser::parse(&mut working_set, None, &contents.into_bytes(), false, &[]); let (block, err) = nu_parser::parse(&mut working_set, None, &contents.into_bytes(), false, &[]);

@ -1,5 +1,5 @@
use embed_nu::{rusty_value::*, IntoValue}; use embed_nu::{rusty_value::*, IntoValue};
use embed_nu::{CommandGroupConfig, Context, NewEmpty, PipelineData}; use embed_nu::{CommandGroupConfig, Context, PipelineData};
use nu_protocol::engine::Command; use nu_protocol::engine::Command;
use nu_protocol::{Config, Signature, SyntaxShape}; use nu_protocol::{Config, Signature, SyntaxShape};

Loading…
Cancel
Save