forked from extern/nushell
Merge master
This commit is contained in:
commit
d629686a4b
@ -20,6 +20,9 @@ steps:
|
|||||||
export PATH=$HOME/.cargo/bin:$PATH
|
export PATH=$HOME/.cargo/bin:$PATH
|
||||||
rustc -Vv
|
rustc -Vv
|
||||||
echo "##vso[task.prependpath]$HOME/.cargo/bin"
|
echo "##vso[task.prependpath]$HOME/.cargo/bin"
|
||||||
|
rustup component add rustfmt --toolchain `cat rust-toolchain`
|
||||||
displayName: Install Rust
|
displayName: Install Rust
|
||||||
- bash: RUSTFLAGS="-D warnings" cargo test --all-features
|
- bash: RUSTFLAGS="-D warnings" cargo test --all-features
|
||||||
displayName: Run tests
|
displayName: Run tests
|
||||||
|
- bash: cargo fmt --all -- --check
|
||||||
|
displayName: Lint
|
||||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1542,7 +1542,6 @@ dependencies = [
|
|||||||
"prettytable-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"prettytable-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ptree 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ptree 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rawkey 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rawkey 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"roxmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"roxmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rusqlite 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rusqlite 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustyline 5.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustyline 5.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -59,7 +59,6 @@ unicode-xid = "0.2.0"
|
|||||||
serde_ini = "0.2.0"
|
serde_ini = "0.2.0"
|
||||||
subprocess = "0.1.18"
|
subprocess = "0.1.18"
|
||||||
mime = "0.3.13"
|
mime = "0.3.13"
|
||||||
regex = "1.2.1"
|
|
||||||
pretty-hex = "0.1.0"
|
pretty-hex = "0.1.0"
|
||||||
hex = "0.3.2"
|
hex = "0.3.2"
|
||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
|
@ -2,5 +2,7 @@ ARG FROMTAG=latest
|
|||||||
FROM quay.io/nushell/nu-base:${FROMTAG} as base
|
FROM quay.io/nushell/nu-base:${FROMTAG} as base
|
||||||
FROM rust:1.37-slim
|
FROM rust:1.37-slim
|
||||||
COPY --from=base /usr/local/bin/nu /usr/local/bin/nu
|
COPY --from=base /usr/local/bin/nu /usr/local/bin/nu
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y pkg-config libssl-dev
|
||||||
ENTRYPOINT ["nu"]
|
ENTRYPOINT ["nu"]
|
||||||
CMD ["-l", "info"]
|
CMD ["-l", "info"]
|
||||||
|
@ -7,6 +7,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
|||||||
RUN apt-get update && apt-get install -y libssl-dev \
|
RUN apt-get update && apt-get install -y libssl-dev \
|
||||||
libxcb-composite0-dev \
|
libxcb-composite0-dev \
|
||||||
libx11-dev \
|
libx11-dev \
|
||||||
|
libssl-dev \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
curl
|
curl
|
||||||
|
|
||||||
|
107
src/cli.rs
107
src/cli.rs
@ -15,7 +15,6 @@ use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode};
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use regex::Regex;
|
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::{self, config::Configurer, config::EditMode, ColorMode, Config, Editor};
|
use rustyline::{self, config::Configurer, config::EditMode, ColorMode, Config, Editor};
|
||||||
use std::env;
|
use std::env;
|
||||||
@ -98,38 +97,12 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_plugins_in_dir(path: &std::path::PathBuf, context: &mut Context) -> Result<(), ShellError> {
|
fn search_paths() -> Vec<std::path::PathBuf> {
|
||||||
let re_bin = Regex::new(r"^nu_plugin_[A-Za-z_]+$")?;
|
let mut search_paths = Vec::new();
|
||||||
let re_exe = Regex::new(r"^nu_plugin_[A-Za-z_]+\.(exe|bat)$")?;
|
|
||||||
|
|
||||||
trace!("Looking for plugins in {:?}", path);
|
|
||||||
|
|
||||||
match std::fs::read_dir(path) {
|
|
||||||
Ok(p) => {
|
|
||||||
for entry in p {
|
|
||||||
let entry = entry?;
|
|
||||||
let filename = entry.file_name();
|
|
||||||
let f_name = filename.to_string_lossy();
|
|
||||||
|
|
||||||
if re_bin.is_match(&f_name) || re_exe.is_match(&f_name) {
|
|
||||||
let mut load_path = path.clone();
|
|
||||||
trace!("Found {:?}", f_name);
|
|
||||||
load_path.push(f_name.to_string());
|
|
||||||
load_plugin(&load_path, context)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
|
|
||||||
match env::var_os("PATH") {
|
match env::var_os("PATH") {
|
||||||
Some(paths) => {
|
Some(paths) => {
|
||||||
for path in env::split_paths(&paths) {
|
search_paths = env::split_paths(&paths).collect::<Vec<_>>();
|
||||||
let _ = load_plugins_in_dir(&path, context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => println!("PATH is not defined in the environment."),
|
None => println!("PATH is not defined in the environment."),
|
||||||
}
|
}
|
||||||
@ -140,7 +113,7 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
|
|||||||
let mut path = std::path::PathBuf::from(".");
|
let mut path = std::path::PathBuf::from(".");
|
||||||
path.push("target");
|
path.push("target");
|
||||||
path.push("debug");
|
path.push("debug");
|
||||||
let _ = load_plugins_in_dir(&path, context);
|
search_paths.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
@ -149,8 +122,78 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
|
|||||||
let mut path = std::path::PathBuf::from(".");
|
let mut path = std::path::PathBuf::from(".");
|
||||||
path.push("target");
|
path.push("target");
|
||||||
path.push("release");
|
path.push("release");
|
||||||
|
search_paths.push(path);
|
||||||
|
}
|
||||||
|
|
||||||
let _ = load_plugins_in_dir(&path, context);
|
search_paths
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
|
||||||
|
let opts = glob::MatchOptions {
|
||||||
|
case_sensitive: false,
|
||||||
|
require_literal_separator: false,
|
||||||
|
require_literal_leading_dot: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
for path in search_paths() {
|
||||||
|
let mut pattern = path.to_path_buf();
|
||||||
|
|
||||||
|
pattern.push(std::path::Path::new("nu_plugin_[a-z]*"));
|
||||||
|
|
||||||
|
match glob::glob_with(&pattern.to_string_lossy(), opts) {
|
||||||
|
Err(_) => {}
|
||||||
|
Ok(binaries) => {
|
||||||
|
for bin in binaries.filter_map(Result::ok) {
|
||||||
|
if !bin.is_file() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bin_name = {
|
||||||
|
if let Some(name) = bin.file_name() {
|
||||||
|
match name.to_str() {
|
||||||
|
Some(raw) => raw,
|
||||||
|
None => continue,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let is_valid_name = {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
bin_name
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphabetic() || c == '_' || c == '.')
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
bin_name
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphabetic() || c == '_')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let is_executable = {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
bin_name.ends_with(".exe") || bin_name.ends_with(".bat")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if is_valid_name && is_executable {
|
||||||
|
trace!("Trying {:?}", bin.display());
|
||||||
|
load_plugin(&bin, context)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -10,8 +10,7 @@ impl WholeStreamCommand for CD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("cd")
|
Signature::build("cd").optional("directory", SyntaxType::Path)
|
||||||
.optional("directory", SyntaxType::Path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{Dictionary, Value};
|
use crate::data::{Dictionary, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use chrono::{DateTime, Local, Utc};
|
use chrono::{DateTime, Local, Utc};
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ impl WholeStreamCommand for Exit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("exit")
|
Signature::build("exit").switch("now")
|
||||||
.switch("now")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -16,8 +16,7 @@ impl WholeStreamCommand for First {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("first")
|
Signature::build("first").required("amount", SyntaxType::Literal)
|
||||||
.required("amount", SyntaxType::Literal)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Get;
|
pub struct Get;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct GetArgs {
|
pub struct GetArgs {
|
||||||
|
member: Tagged<String>,
|
||||||
rest: Vec<Tagged<String>>,
|
rest: Vec<Tagged<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,7 +17,9 @@ impl WholeStreamCommand for Get {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("get").rest(SyntaxType::Member)
|
Signature::build("get")
|
||||||
|
.required("member", SyntaxType::Member)
|
||||||
|
.rest(SyntaxType::Member)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
@ -63,13 +66,24 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(
|
pub fn get(
|
||||||
GetArgs { rest: fields }: GetArgs,
|
GetArgs {
|
||||||
|
member,
|
||||||
|
rest: fields,
|
||||||
|
}: GetArgs,
|
||||||
RunnableContext { input, .. }: RunnableContext,
|
RunnableContext { input, .. }: RunnableContext,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let stream = input
|
let stream = input
|
||||||
.values
|
.values
|
||||||
.map(move |item| {
|
.map(move |item| {
|
||||||
let mut result = VecDeque::new();
|
let mut result = VecDeque::new();
|
||||||
|
|
||||||
|
let member = vec![member.clone()];
|
||||||
|
|
||||||
|
let fields = vec![&member, &fields]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.collect::<Vec<&Tagged<String>>>();
|
||||||
|
|
||||||
for field in &fields {
|
for field in &fields {
|
||||||
match get_member(field, &item) {
|
match get_member(field, &item) {
|
||||||
Ok(Tagged {
|
Ok(Tagged {
|
||||||
|
@ -101,20 +101,6 @@ impl PerItemCommand for Help {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub struct Signature {
|
|
||||||
// pub name: String,
|
|
||||||
// #[new(default)]
|
|
||||||
// pub usage: String,
|
|
||||||
// #[new(default)]
|
|
||||||
// pub positional: Vec<PositionalType>,
|
|
||||||
// #[new(value = "None")]
|
|
||||||
// pub rest_positional: Option<SyntaxType>,
|
|
||||||
// #[new(default)]
|
|
||||||
// pub named: IndexMap<String, NamedType>,
|
|
||||||
// #[new(value = "false")]
|
|
||||||
// pub is_filter: bool,
|
|
||||||
// }
|
|
||||||
|
|
||||||
help.push_back(ReturnSuccess::value(
|
help.push_back(ReturnSuccess::value(
|
||||||
Value::string(long_desc).tagged(tag.clone()),
|
Value::string(long_desc).tagged(tag.clone()),
|
||||||
));
|
));
|
||||||
@ -125,9 +111,11 @@ impl PerItemCommand for Help {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let msg = r#"Welcome to Nushell.
|
let msg = r#"Welcome to Nushell.
|
||||||
|
|
||||||
Here are some tips to help you get started.
|
Here are some tips to help you get started.
|
||||||
* help commands - list all available commands
|
* help commands - list all available commands
|
||||||
* help <command name> - display help about a particular command
|
* help <command name> - display help about a particular command
|
||||||
|
|
||||||
You can also learn more at http://book.nushell.sh"#;
|
You can also learn more at http://book.nushell.sh"#;
|
||||||
|
|
||||||
let mut output_stream = VecDeque::new();
|
let mut output_stream = VecDeque::new();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::context::CommandRegistry;
|
use crate::context::CommandRegistry;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::base::select_fields;
|
use crate::data::base::select_fields;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::base::reject_fields;
|
use crate::data::base::reject_fields;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::TaggedDictBuilder;
|
use crate::data::TaggedDictBuilder;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Shells;
|
pub struct Shells;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Size;
|
pub struct Size;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
use crate::data::{Primitive, TaggedDictBuilder, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
@ -40,7 +40,11 @@ impl WholeStreamCommand for SplitColumn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn split_column(
|
fn split_column(
|
||||||
SplitColumnArgs { separator, rest, collapse_empty}: SplitColumnArgs,
|
SplitColumnArgs {
|
||||||
|
separator,
|
||||||
|
rest,
|
||||||
|
collapse_empty,
|
||||||
|
}: SplitColumnArgs,
|
||||||
RunnableContext { input, name, .. }: RunnableContext,
|
RunnableContext { input, name, .. }: RunnableContext,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
Ok(input
|
Ok(input
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{Primitive, Value};
|
use crate::data::{Primitive, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
@ -17,8 +17,7 @@ impl WholeStreamCommand for SplitRow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("split-row")
|
Signature::build("split-row").required("separator", SyntaxType::Any)
|
||||||
.required("separator", SyntaxType::Any)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{TaggedDictBuilder, Value};
|
use crate::data::{TaggedDictBuilder, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Tags;
|
pub struct Tags;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub struct Trim;
|
pub struct Trim;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{Dictionary, Value};
|
use crate::data::{Dictionary, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::parser::registry::Signature;
|
use crate::parser::registry::Signature;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -12,8 +12,7 @@ impl PerItemCommand for Where {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> registry::Signature {
|
fn signature(&self) -> registry::Signature {
|
||||||
Signature::build("where")
|
Signature::build("where").required("condition", SyntaxType::Block)
|
||||||
.required("condition", SyntaxType::Block)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
@ -43,9 +42,7 @@ impl PerItemCommand for Where {
|
|||||||
VecDeque::new()
|
VecDeque::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => return Err(e),
|
||||||
return Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tagged { tag, .. } => {
|
Tagged { tag, .. } => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
@ -13,8 +13,7 @@ impl WholeStreamCommand for Which {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("which")
|
Signature::build("which").required("name", SyntaxType::Any)
|
||||||
.required("name", SyntaxType::Any)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
|
@ -555,16 +555,6 @@ impl std::convert::From<serde_json::Error> for ShellError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<regex::Error> for ShellError {
|
|
||||||
fn from(input: regex::Error) -> ShellError {
|
|
||||||
ProximateShellError::String(StringError {
|
|
||||||
title: format!("{:?}", input),
|
|
||||||
error: Value::nothing(),
|
|
||||||
})
|
|
||||||
.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::convert::From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
impl std::convert::From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
||||||
fn from(input: Box<dyn std::error::Error + Send + Sync>) -> ShellError {
|
fn from(input: Box<dyn std::error::Error + Send + Sync>) -> ShellError {
|
||||||
ProximateShellError::String(StringError {
|
ProximateShellError::String(StringError {
|
||||||
|
@ -28,8 +28,8 @@ pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
|
|||||||
pub use crate::plugin::{serve_plugin, Plugin};
|
pub use crate::plugin::{serve_plugin, Plugin};
|
||||||
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
|
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
|
||||||
pub use cli::cli;
|
pub use cli::cli;
|
||||||
pub use data::config::{APP_INFO, config_path};
|
|
||||||
pub use data::base::{Primitive, Value};
|
pub use data::base::{Primitive, Value};
|
||||||
|
pub use data::config::{config_path, APP_INFO};
|
||||||
pub use data::dict::{Dictionary, TaggedDictBuilder};
|
pub use data::dict::{Dictionary, TaggedDictBuilder};
|
||||||
pub use data::meta::{Span, Tag, Tagged, TaggedItem};
|
pub use data::meta::{Span, Tag, Tagged, TaggedItem};
|
||||||
pub use errors::{CoerceInto, ShellError};
|
pub use errors::{CoerceInto, ShellError};
|
||||||
|
@ -20,7 +20,6 @@ impl ToDebug for Operator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Operator {
|
impl Operator {
|
||||||
|
|
||||||
pub fn print(&self) -> String {
|
pub fn print(&self) -> String {
|
||||||
self.as_str().to_string()
|
self.as_str().to_string()
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,12 @@ use nu::{
|
|||||||
serve_plugin, CallInfo, Plugin, Primitive, ReturnSuccess, ReturnValue, ShellError, Signature,
|
serve_plugin, CallInfo, Plugin, Primitive, ReturnSuccess, ReturnValue, ShellError, Signature,
|
||||||
SyntaxType, Tagged, Value,
|
SyntaxType, Tagged, Value,
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
enum Action {
|
enum Action {
|
||||||
Downcase,
|
Downcase,
|
||||||
Upcase,
|
Upcase,
|
||||||
ToInteger,
|
ToInteger,
|
||||||
Replace(ReplaceAction),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
enum ReplaceAction {
|
|
||||||
Direct,
|
|
||||||
FindAndReplace,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Str {
|
struct Str {
|
||||||
@ -45,41 +37,12 @@ impl Str {
|
|||||||
Err(_) => Value::string(input),
|
Err(_) => Value::string(input),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Some(Action::Replace(ref mode)) => match mode {
|
|
||||||
ReplaceAction::Direct => Value::string(self.first_param()),
|
|
||||||
ReplaceAction::FindAndReplace => {
|
|
||||||
let regex = Regex::new(self.first_param());
|
|
||||||
|
|
||||||
match regex {
|
|
||||||
Ok(re) => Value::string(re.replace(input, self.second_param()).to_owned()),
|
|
||||||
Err(_) => Value::string(input),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => Value::string(input),
|
None => Value::string(input),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(applied)
|
Ok(applied)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_supply_field(&self) -> bool {
|
|
||||||
self.field.is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn first_param(&self) -> &str {
|
|
||||||
let idx = if self.did_supply_field() { 1 } else { 0 };
|
|
||||||
self.get_param(idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn second_param(&self) -> &str {
|
|
||||||
let idx = if self.did_supply_field() { 2 } else { 1 };
|
|
||||||
self.get_param(idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_param(&self, idx: usize) -> &str {
|
|
||||||
self.params.as_ref().unwrap().get(idx).unwrap().as_str()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn for_field(&mut self, field: &str) {
|
fn for_field(&mut self, field: &str) {
|
||||||
self.field = Some(String::from(field));
|
self.field = Some(String::from(field));
|
||||||
}
|
}
|
||||||
@ -92,14 +55,6 @@ impl Str {
|
|||||||
self.error = Some(message.to_string());
|
self.error = Some(message.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_replace(&mut self, mode: ReplaceAction) {
|
|
||||||
if self.permit() {
|
|
||||||
self.action = Some(Action::Replace(mode));
|
|
||||||
} else {
|
|
||||||
self.log_error("can only apply one");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn for_to_int(&mut self) {
|
fn for_to_int(&mut self) {
|
||||||
if self.permit() {
|
if self.permit() {
|
||||||
self.action = Some(Action::ToInteger);
|
self.action = Some(Action::ToInteger);
|
||||||
@ -125,7 +80,7 @@ impl Str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn usage() -> &'static str {
|
pub fn usage() -> &'static str {
|
||||||
"Usage: str field [--downcase|--upcase|--to-int|--replace|--find-replace]"
|
"Usage: str field [--downcase|--upcase|--to-int]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,8 +127,6 @@ impl Plugin for Str {
|
|||||||
.switch("downcase")
|
.switch("downcase")
|
||||||
.switch("upcase")
|
.switch("upcase")
|
||||||
.switch("to-int")
|
.switch("to-int")
|
||||||
.switch("replace")
|
|
||||||
.switch("find-replace")
|
|
||||||
.rest(SyntaxType::Member)
|
.rest(SyntaxType::Member)
|
||||||
.filter())
|
.filter())
|
||||||
}
|
}
|
||||||
@ -190,12 +143,6 @@ impl Plugin for Str {
|
|||||||
if args.has("to-int") {
|
if args.has("to-int") {
|
||||||
self.for_to_int();
|
self.for_to_int();
|
||||||
}
|
}
|
||||||
if args.has("replace") {
|
|
||||||
self.for_replace(ReplaceAction::Direct);
|
|
||||||
}
|
|
||||||
if args.has("find-replace") {
|
|
||||||
self.for_replace(ReplaceAction::FindAndReplace);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(possible_field) = args.nth(0) {
|
if let Some(possible_field) = args.nth(0) {
|
||||||
match possible_field {
|
match possible_field {
|
||||||
@ -203,16 +150,6 @@ impl Plugin for Str {
|
|||||||
item: Value::Primitive(Primitive::String(s)),
|
item: Value::Primitive(Primitive::String(s)),
|
||||||
..
|
..
|
||||||
} => match self.action {
|
} => match self.action {
|
||||||
Some(Action::Replace(ReplaceAction::Direct)) => {
|
|
||||||
if args.len() == 2 {
|
|
||||||
self.for_field(&s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Action::Replace(ReplaceAction::FindAndReplace)) => {
|
|
||||||
if args.len() == 3 {
|
|
||||||
self.for_field(&s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Action::Downcase)
|
Some(Action::Downcase)
|
||||||
| Some(Action::Upcase)
|
| Some(Action::Upcase)
|
||||||
| Some(Action::ToInteger)
|
| Some(Action::ToInteger)
|
||||||
@ -258,7 +195,7 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Action, ReplaceAction, Str};
|
use super::{Action, Str};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu::{
|
use nu::{
|
||||||
CallInfo, EvaluatedArgs, Plugin, Primitive, ReturnSuccess, SourceMap, Span, Tag, Tagged,
|
CallInfo, EvaluatedArgs, Plugin, Primitive, ReturnSuccess, SourceMap, Span, Tag, Tagged,
|
||||||
@ -266,16 +203,6 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
impl Str {
|
|
||||||
fn replace_with(&mut self, value: &str) {
|
|
||||||
self.params.as_mut().unwrap().push(value.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_with(&mut self, search: &str) {
|
|
||||||
self.params.as_mut().unwrap().push(search.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CallStub {
|
struct CallStub {
|
||||||
positionals: Vec<Tagged<Value>>,
|
positionals: Vec<Tagged<Value>>,
|
||||||
flags: IndexMap<String, Tagged<Value>>,
|
flags: IndexMap<String, Tagged<Value>>,
|
||||||
@ -328,7 +255,7 @@ mod tests {
|
|||||||
|
|
||||||
let configured = plugin.config().unwrap();
|
let configured = plugin.config().unwrap();
|
||||||
|
|
||||||
for action_flag in &["downcase", "upcase", "to-int", "replace", "find-replace"] {
|
for action_flag in &["downcase", "upcase", "to-int"] {
|
||||||
assert!(configured.named.get(*action_flag).is_some());
|
assert!(configured.named.get(*action_flag).is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,33 +289,6 @@ mod tests {
|
|||||||
.is_ok());
|
.is_ok());
|
||||||
assert_eq!(plugin.action.unwrap(), Action::ToInteger);
|
assert_eq!(plugin.action.unwrap(), Action::ToInteger);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_accepts_replace() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(CallStub::new().with_long_flag("replace").create())
|
|
||||||
.is_ok());
|
|
||||||
assert_eq!(
|
|
||||||
plugin.action.unwrap(),
|
|
||||||
Action::Replace(ReplaceAction::Direct)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_accepts_find_replace() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(CallStub::new().with_long_flag("find-replace").create())
|
|
||||||
.is_ok());
|
|
||||||
assert_eq!(
|
|
||||||
plugin.action.unwrap(),
|
|
||||||
Action::Replace(ReplaceAction::FindAndReplace)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn str_plugin_accepts_field() {
|
fn str_plugin_accepts_field() {
|
||||||
let mut plugin = Str::new();
|
let mut plugin = Str::new();
|
||||||
@ -441,26 +341,6 @@ mod tests {
|
|||||||
assert_eq!(strutils.apply("9999").unwrap(), Value::int(9999 as i64));
|
assert_eq!(strutils.apply("9999").unwrap(), Value::int(9999 as i64));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_replace() {
|
|
||||||
let mut strutils = Str::new();
|
|
||||||
strutils.for_replace(ReplaceAction::Direct);
|
|
||||||
strutils.replace_with("robalino");
|
|
||||||
assert_eq!(strutils.apply("andres").unwrap(), Value::string("robalino"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_find_replace() {
|
|
||||||
let mut strutils = Str::new();
|
|
||||||
strutils.for_replace(ReplaceAction::FindAndReplace);
|
|
||||||
strutils.find_with(r"kittens");
|
|
||||||
strutils.replace_with("jotandrehuda");
|
|
||||||
assert_eq!(
|
|
||||||
strutils.apply("wykittens").unwrap(),
|
|
||||||
Value::string("wyjotandrehuda")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn str_plugin_applies_upcase_with_field() {
|
fn str_plugin_applies_upcase_with_field() {
|
||||||
let mut plugin = Str::new();
|
let mut plugin = Str::new();
|
||||||
@ -604,114 +484,4 @@ mod tests {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_applies_replace_with_field() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(
|
|
||||||
CallStub::new()
|
|
||||||
.with_parameter("rustconf")
|
|
||||||
.with_parameter("22nd August 2019")
|
|
||||||
.with_long_flag("replace")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
let subject = structured_sample_record("rustconf", "1st January 1970");
|
|
||||||
let output = plugin.filter(subject).unwrap();
|
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
|
||||||
ReturnSuccess::Value(Tagged {
|
|
||||||
item: Value::Row(o),
|
|
||||||
..
|
|
||||||
}) => assert_eq!(
|
|
||||||
*o.get_data(&String::from("rustconf")).borrow(),
|
|
||||||
Value::string(String::from("22nd August 2019"))
|
|
||||||
),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_applies_replace_without_field() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(
|
|
||||||
CallStub::new()
|
|
||||||
.with_parameter("22nd August 2019")
|
|
||||||
.with_long_flag("replace")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
let subject = unstructured_sample_record("1st January 1970");
|
|
||||||
let output = plugin.filter(subject).unwrap();
|
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
|
||||||
ReturnSuccess::Value(Tagged {
|
|
||||||
item: Value::Primitive(Primitive::String(s)),
|
|
||||||
..
|
|
||||||
}) => assert_eq!(*s, String::from("22nd August 2019")),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_applies_find_replace_with_field() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(
|
|
||||||
CallStub::new()
|
|
||||||
.with_parameter("staff")
|
|
||||||
.with_parameter("kittens")
|
|
||||||
.with_parameter("jotandrehuda")
|
|
||||||
.with_long_flag("find-replace")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
let subject = structured_sample_record("staff", "wykittens");
|
|
||||||
let output = plugin.filter(subject).unwrap();
|
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
|
||||||
ReturnSuccess::Value(Tagged {
|
|
||||||
item: Value::Row(o),
|
|
||||||
..
|
|
||||||
}) => assert_eq!(
|
|
||||||
*o.get_data(&String::from("staff")).borrow(),
|
|
||||||
Value::string(String::from("wyjotandrehuda"))
|
|
||||||
),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn str_plugin_applies_find_replace_without_field() {
|
|
||||||
let mut plugin = Str::new();
|
|
||||||
|
|
||||||
assert!(plugin
|
|
||||||
.begin_filter(
|
|
||||||
CallStub::new()
|
|
||||||
.with_parameter("kittens")
|
|
||||||
.with_parameter("jotandrehuda")
|
|
||||||
.with_long_flag("find-replace")
|
|
||||||
.create()
|
|
||||||
)
|
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
let subject = unstructured_sample_record("wykittens");
|
|
||||||
let output = plugin.filter(subject).unwrap();
|
|
||||||
|
|
||||||
match output[0].as_ref().unwrap() {
|
|
||||||
ReturnSuccess::Value(Tagged {
|
|
||||||
item: Value::Primitive(Primitive::String(s)),
|
|
||||||
..
|
|
||||||
}) => assert_eq!(*s, String::from("wyjotandrehuda")),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
pub(crate) mod completer;
|
pub(crate) mod completer;
|
||||||
pub(crate) mod filesystem_shell;
|
pub(crate) mod filesystem_shell;
|
||||||
|
pub(crate) mod help_shell;
|
||||||
pub(crate) mod helper;
|
pub(crate) mod helper;
|
||||||
pub(crate) mod shell;
|
pub(crate) mod shell;
|
||||||
pub(crate) mod shell_manager;
|
pub(crate) mod shell_manager;
|
||||||
pub(crate) mod value_shell;
|
pub(crate) mod value_shell;
|
||||||
pub(crate) mod help_shell;
|
|
||||||
|
|
||||||
pub(crate) use helper::Helper;
|
pub(crate) use helper::Helper;
|
||||||
|
@ -207,8 +207,7 @@ impl Shell for FilesystemShell {
|
|||||||
|
|
||||||
let mut stream = VecDeque::new();
|
let mut stream = VecDeque::new();
|
||||||
|
|
||||||
stream.push_back(
|
stream.push_back(ReturnSuccess::change_cwd(
|
||||||
ReturnSuccess::change_cwd(
|
|
||||||
path.to_string_lossy().to_string(),
|
path.to_string_lossy().to_string(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -113,7 +113,10 @@ fn filesystem_change_to_a_directory_containing_spaces() {
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(PathBuf::from(actual), dirs.test().join("robalino turner katz"));
|
assert_eq!(
|
||||||
|
PathBuf::from(actual),
|
||||||
|
dirs.test().join("robalino turner katz")
|
||||||
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,12 +131,10 @@ fn filesystem_directory_not_found() {
|
|||||||
assert!(actual.contains("directory not found"));
|
assert!(actual.contains("directory not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_from_current_path_using_relative_path() {
|
fn valuesystem_change_from_current_path_using_relative_path() {
|
||||||
Playground::setup("cd_test_8", |dirs, sandbox| {
|
Playground::setup("cd_test_8", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
@ -144,7 +145,7 @@ fn valuesystem_change_from_current_path_using_relative_path() {
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/plugins/katz.rs"
|
path = "src/plugins/katz.rs"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -164,8 +165,7 @@ fn valuesystem_change_from_current_path_using_relative_path() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_from_current_path_using_absolute_path() {
|
fn valuesystem_change_from_current_path_using_absolute_path() {
|
||||||
Playground::setup("cd_test_9", |dirs, sandbox| {
|
Playground::setup("cd_test_9", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -178,7 +178,7 @@ fn valuesystem_change_from_current_path_using_absolute_path() {
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/plugins/bbq.rs"
|
path = "src/plugins/bbq.rs"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -199,8 +199,7 @@ fn valuesystem_change_from_current_path_using_absolute_path() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_switch_back_to_previous_working_path() {
|
fn valuesystem_switch_back_to_previous_working_path() {
|
||||||
Playground::setup("cd_test_10", |dirs, sandbox| {
|
Playground::setup("cd_test_10", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -214,7 +213,7 @@ fn valuesystem_switch_back_to_previous_working_path() {
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/plugins/bbq.rs"
|
path = "src/plugins/bbq.rs"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -267,7 +266,6 @@ fn valuesystem_change_from_current_path_using_relative_path_and_dash() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_current_path_to_parent_path() {
|
fn valuesystem_change_current_path_to_parent_path() {
|
||||||
Playground::setup("cd_test_12", |dirs, sandbox| {
|
Playground::setup("cd_test_12", |dirs, sandbox| {
|
||||||
@ -298,13 +296,12 @@ fn valuesystem_change_current_path_to_parent_path() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_to_home_directory() {
|
fn valuesystem_change_to_home_directory() {
|
||||||
Playground::setup("cd_test_13", |dirs, sandbox| {
|
Playground::setup("cd_test_13", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[paquete]
|
[paquete]
|
||||||
el = "pollo loco"
|
el = "pollo loco"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -325,13 +322,12 @@ fn valuesystem_change_to_home_directory() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn valuesystem_change_to_a_path_containing_spaces() {
|
fn valuesystem_change_to_a_path_containing_spaces() {
|
||||||
Playground::setup("cd_test_14", |dirs, sandbox| {
|
Playground::setup("cd_test_14", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
["pa que te"]
|
["pa que te"]
|
||||||
el = "pollo loco"
|
el = "pollo loco"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
@ -10,7 +10,6 @@ fn has_default_configuration_file() {
|
|||||||
let expected = "config.toml";
|
let expected = "config.toml";
|
||||||
|
|
||||||
Playground::setup("config_test_1", |dirs, _| {
|
Playground::setup("config_test_1", |dirs, _| {
|
||||||
|
|
||||||
nu!(cwd: dirs.root(), "config");
|
nu!(cwd: dirs.root(), "config");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -25,7 +24,6 @@ fn shows_path_of_configuration_file() {
|
|||||||
let expected = "config.toml";
|
let expected = "config.toml";
|
||||||
|
|
||||||
Playground::setup("config_test_2", |dirs, _| {
|
Playground::setup("config_test_2", |dirs, _| {
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"config --path | echo $it"
|
"config --path | echo $it"
|
||||||
@ -38,14 +36,13 @@ fn shows_path_of_configuration_file() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn use_different_configuration() {
|
fn use_different_configuration() {
|
||||||
Playground::setup("config_test_3", |dirs, sandbox| {
|
Playground::setup("config_test_3", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"test_3.toml",
|
"test_3.toml",
|
||||||
r#"
|
r#"
|
||||||
caballero_1 = "Andrés N. Robalino"
|
caballero_1 = "Andrés N. Robalino"
|
||||||
caballero_2 = "Jonathan Turner"
|
caballero_2 = "Jonathan Turner"
|
||||||
caballero_3 = "Yehuda katz"
|
caballero_3 = "Yehuda katz"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -63,14 +60,13 @@ fn use_different_configuration() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn sets_configuration_value() {
|
fn sets_configuration_value() {
|
||||||
Playground::setup("config_test_4", |dirs, sandbox| {
|
Playground::setup("config_test_4", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"test_4.toml",
|
"test_4.toml",
|
||||||
r#"
|
r#"
|
||||||
caballero_1 = "Andrés N. Robalino"
|
caballero_1 = "Andrés N. Robalino"
|
||||||
caballero_2 = "Jonathan Turner"
|
caballero_2 = "Jonathan Turner"
|
||||||
caballero_3 = "Yehuda katz"
|
caballero_3 = "Yehuda katz"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
@ -93,13 +89,12 @@ fn sets_configuration_value() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn removes_configuration_value() {
|
fn removes_configuration_value() {
|
||||||
Playground::setup("config_test_5", |dirs, sandbox| {
|
Playground::setup("config_test_5", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"test_5.toml",
|
"test_5.toml",
|
||||||
r#"
|
r#"
|
||||||
caballeros = [1, 1, 1]
|
caballeros = [1, 1, 1]
|
||||||
podershell = [1, 1, 1]
|
podershell = [1, 1, 1]
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
|
@ -6,8 +6,7 @@ use helpers::{Playground, Stub::*};
|
|||||||
#[test]
|
#[test]
|
||||||
fn ls_lists_regular_files() {
|
fn ls_lists_regular_files() {
|
||||||
Playground::setup("ls_test_1", |dirs, sandbox| {
|
Playground::setup("ls_test_1", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![
|
||||||
.with_files(vec![
|
|
||||||
EmptyFile("yehuda.10.txt"),
|
EmptyFile("yehuda.10.txt"),
|
||||||
EmptyFile("jonathan.10.txt"),
|
EmptyFile("jonathan.10.txt"),
|
||||||
EmptyFile("andres.10.txt"),
|
EmptyFile("andres.10.txt"),
|
||||||
@ -34,8 +33,7 @@ fn ls_lists_regular_files() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ls_lists_regular_files_using_asterisk_wildcard() {
|
fn ls_lists_regular_files_using_asterisk_wildcard() {
|
||||||
Playground::setup("ls_test_2", |dirs, sandbox| {
|
Playground::setup("ls_test_2", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![
|
||||||
.with_files(vec![
|
|
||||||
EmptyFile("los.1.txt"),
|
EmptyFile("los.1.txt"),
|
||||||
EmptyFile("tres.1.txt"),
|
EmptyFile("tres.1.txt"),
|
||||||
EmptyFile("amigos.1.txt"),
|
EmptyFile("amigos.1.txt"),
|
||||||
@ -63,8 +61,7 @@ fn ls_lists_regular_files_using_asterisk_wildcard() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ls_lists_regular_files_using_question_mark_wildcard() {
|
fn ls_lists_regular_files_using_question_mark_wildcard() {
|
||||||
Playground::setup("ls_test_3", |dirs, sandbox| {
|
Playground::setup("ls_test_3", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![
|
||||||
.with_files(vec![
|
|
||||||
EmptyFile("yehuda.10.txt"),
|
EmptyFile("yehuda.10.txt"),
|
||||||
EmptyFile("jonathan.10.txt"),
|
EmptyFile("jonathan.10.txt"),
|
||||||
EmptyFile("andres.10.txt"),
|
EmptyFile("andres.10.txt"),
|
||||||
|
@ -26,11 +26,7 @@ fn moves_a_file() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn overwrites_if_moving_to_existing_file() {
|
fn overwrites_if_moving_to_existing_file() {
|
||||||
Playground::setup("mv_test_2", |dirs, sandbox| {
|
Playground::setup("mv_test_2", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![EmptyFile("andres.txt"), EmptyFile("jonathan.txt")]);
|
||||||
.with_files(vec![
|
|
||||||
EmptyFile("andres.txt"),
|
|
||||||
EmptyFile("jonathan.txt")
|
|
||||||
]);
|
|
||||||
|
|
||||||
let original = dirs.test().join("andres.txt");
|
let original = dirs.test().join("andres.txt");
|
||||||
let expected = dirs.test().join("jonathan.txt");
|
let expected = dirs.test().join("jonathan.txt");
|
||||||
@ -142,7 +138,7 @@ fn moves_using_path_with_wildcard() {
|
|||||||
EmptyFile("sgml_description.json"),
|
EmptyFile("sgml_description.json"),
|
||||||
EmptyFile("sample.ini"),
|
EmptyFile("sample.ini"),
|
||||||
EmptyFile("utf16.ini"),
|
EmptyFile("utf16.ini"),
|
||||||
EmptyFile("yehuda.ini")
|
EmptyFile("yehuda.ini"),
|
||||||
])
|
])
|
||||||
.mkdir("work_dir")
|
.mkdir("work_dir")
|
||||||
.mkdir("expected");
|
.mkdir("expected");
|
||||||
@ -150,10 +146,7 @@ fn moves_using_path_with_wildcard() {
|
|||||||
let work_dir = dirs.test().join("work_dir");
|
let work_dir = dirs.test().join("work_dir");
|
||||||
let expected = dirs.test().join("expected");
|
let expected = dirs.test().join("expected");
|
||||||
|
|
||||||
nu!(
|
nu!(cwd: work_dir, "mv ../originals/*.ini ../expected");
|
||||||
cwd: work_dir,
|
|
||||||
"mv ../originals/*.ini ../expected"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
||||||
@ -170,7 +163,7 @@ fn moves_using_a_glob() {
|
|||||||
.with_files(vec![
|
.with_files(vec![
|
||||||
EmptyFile("arepa.txt"),
|
EmptyFile("arepa.txt"),
|
||||||
EmptyFile("empanada.txt"),
|
EmptyFile("empanada.txt"),
|
||||||
EmptyFile("taquiza.txt")
|
EmptyFile("taquiza.txt"),
|
||||||
])
|
])
|
||||||
.mkdir("work_dir")
|
.mkdir("work_dir")
|
||||||
.mkdir("expected");
|
.mkdir("expected");
|
||||||
@ -179,10 +172,7 @@ fn moves_using_a_glob() {
|
|||||||
let work_dir = dirs.test().join("work_dir");
|
let work_dir = dirs.test().join("work_dir");
|
||||||
let expected = dirs.test().join("expected");
|
let expected = dirs.test().join("expected");
|
||||||
|
|
||||||
nu!(
|
nu!(cwd: work_dir, "mv ../meals/* ../expected");
|
||||||
cwd: work_dir,
|
|
||||||
"mv ../meals/* ../expected"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(meal_dir.exists());
|
assert!(meal_dir.exists());
|
||||||
assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
|
@ -6,9 +6,7 @@ use helpers::{Playground, Stub::*};
|
|||||||
#[test]
|
#[test]
|
||||||
fn rm_removes_a_file() {
|
fn rm_removes_a_file() {
|
||||||
Playground::setup("rm_test_1", |dirs, sandbox| {
|
Playground::setup("rm_test_1", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![EmptyFile("i_will_be_deleted.txt")]);
|
||||||
.with_files(vec![EmptyFile("i_will_be_deleted.txt")
|
|
||||||
]);
|
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd: dirs.root(),
|
cwd: dirs.root(),
|
||||||
@ -29,7 +27,7 @@ fn rm_removes_files_with_wildcard() {
|
|||||||
.with_files(vec![
|
.with_files(vec![
|
||||||
EmptyFile("cli.rs"),
|
EmptyFile("cli.rs"),
|
||||||
EmptyFile("lib.rs"),
|
EmptyFile("lib.rs"),
|
||||||
EmptyFile("prelude.rs")
|
EmptyFile("prelude.rs"),
|
||||||
])
|
])
|
||||||
.within("src/parser")
|
.within("src/parser")
|
||||||
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
||||||
@ -38,7 +36,7 @@ fn rm_removes_files_with_wildcard() {
|
|||||||
.within("src/parser/hir")
|
.within("src/parser/hir")
|
||||||
.with_files(vec![
|
.with_files(vec![
|
||||||
EmptyFile("baseline_parse.rs"),
|
EmptyFile("baseline_parse.rs"),
|
||||||
EmptyFile("baseline_parse_tokens.rs")
|
EmptyFile("baseline_parse_tokens.rs"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
@ -70,7 +68,7 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
|||||||
.with_files(vec![
|
.with_files(vec![
|
||||||
EmptyFile("cli.rs"),
|
EmptyFile("cli.rs"),
|
||||||
EmptyFile("lib.rs"),
|
EmptyFile("lib.rs"),
|
||||||
EmptyFile("prelude.rs")
|
EmptyFile("prelude.rs"),
|
||||||
])
|
])
|
||||||
.within("src/parser")
|
.within("src/parser")
|
||||||
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
|
||||||
@ -79,7 +77,7 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
|||||||
.within("src/parser/hir")
|
.within("src/parser/hir")
|
||||||
.with_files(vec![
|
.with_files(vec![
|
||||||
EmptyFile("baseline_parse.rs"),
|
EmptyFile("baseline_parse.rs"),
|
||||||
EmptyFile("baseline_parse_tokens.rs")
|
EmptyFile("baseline_parse_tokens.rs"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
@ -109,11 +107,10 @@ fn rm_removes_directory_contents_without_recursive_flag_if_empty() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn rm_removes_directory_contents_with_recursive_flag() {
|
fn rm_removes_directory_contents_with_recursive_flag() {
|
||||||
Playground::setup("rm_test_5", |dirs, sandbox| {
|
Playground::setup("rm_test_5", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![
|
||||||
.with_files(vec![
|
|
||||||
EmptyFile("yehuda.txt"),
|
EmptyFile("yehuda.txt"),
|
||||||
EmptyFile("jonathan.txt"),
|
EmptyFile("jonathan.txt"),
|
||||||
EmptyFile("andres.txt")
|
EmptyFile("andres.txt"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
@ -128,9 +125,7 @@ fn rm_removes_directory_contents_with_recursive_flag() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() {
|
fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() {
|
||||||
Playground::setup("rm_test_6", |dirs, sandbox| {
|
Playground::setup("rm_test_6", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]);
|
||||||
.with_files(vec![EmptyFile("some_empty_file.txt")
|
|
||||||
]);
|
|
||||||
|
|
||||||
let actual = nu_error!(
|
let actual = nu_error!(
|
||||||
cwd: dirs.root(),
|
cwd: dirs.root(),
|
||||||
|
@ -3,6 +3,119 @@ mod helpers;
|
|||||||
use helpers as h;
|
use helpers as h;
|
||||||
use helpers::{Playground, Stub::*};
|
use helpers::{Playground, Stub::*};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn first_gets_first_rows_by_amount() {
|
||||||
|
Playground::setup("first_test_1", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![
|
||||||
|
EmptyFile("los.1.txt"),
|
||||||
|
EmptyFile("tres.1.txt"),
|
||||||
|
EmptyFile("amigos.1.txt"),
|
||||||
|
EmptyFile("arepas.1.clu"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), h::pipeline(
|
||||||
|
r#"
|
||||||
|
ls
|
||||||
|
| get name
|
||||||
|
| first 2
|
||||||
|
| split-column "."
|
||||||
|
| get Column2
|
||||||
|
| str --to-int
|
||||||
|
| sum
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual, "2");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn first_requires_an_amount() {
|
||||||
|
Playground::setup("first_test_2", |dirs, _| {
|
||||||
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.test(), "ls | first"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(actual.contains("requires amount parameter"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get() {
|
||||||
|
Playground::setup("get_test_1", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![FileWithContent(
|
||||||
|
"sample.toml",
|
||||||
|
r#"
|
||||||
|
nu_party_venue = "zion"
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), h::pipeline(
|
||||||
|
r#"
|
||||||
|
open sample.toml
|
||||||
|
| get nu_party_venue
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual, "zion");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_more_than_one_member() {
|
||||||
|
Playground::setup("get_test_2", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![FileWithContent(
|
||||||
|
"sample.toml",
|
||||||
|
r#"
|
||||||
|
[[fortune_tellers]]
|
||||||
|
name = "Andrés N. Robalino"
|
||||||
|
arepas = 1
|
||||||
|
broken_builds = 0
|
||||||
|
|
||||||
|
[[fortune_tellers]]
|
||||||
|
name = "Jonathan Turner"
|
||||||
|
arepas = 1
|
||||||
|
broken_builds = 1
|
||||||
|
|
||||||
|
[[fortune_tellers]]
|
||||||
|
name = "Yehuda Katz"
|
||||||
|
arepas = 1
|
||||||
|
broken_builds = 1
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), h::pipeline(
|
||||||
|
r#"
|
||||||
|
open sample.toml
|
||||||
|
| get fortune_tellers
|
||||||
|
| get arepas broken_builds
|
||||||
|
| sum
|
||||||
|
| echo $it
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual, "5");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_requires_at_least_one_member() {
|
||||||
|
Playground::setup("first_test_3", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![EmptyFile("andres.txt")]);
|
||||||
|
|
||||||
|
let actual = nu_error!(
|
||||||
|
cwd: dirs.test(), "ls | get"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(actual.contains("requires member parameter"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lines() {
|
fn lines() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
@ -15,13 +15,12 @@ fn can_only_apply_one() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn by_one_with_field_passed() {
|
fn by_one_with_field_passed() {
|
||||||
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_1", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -36,13 +35,12 @@ fn by_one_with_field_passed() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn by_one_with_no_field_passed() {
|
fn by_one_with_no_field_passed() {
|
||||||
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_2", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
contributors = "2"
|
contributors = "2"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -57,13 +55,12 @@ fn by_one_with_no_field_passed() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn semversion_major_inc() {
|
fn semversion_major_inc() {
|
||||||
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_3", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -78,13 +75,12 @@ fn semversion_major_inc() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn semversion_minor_inc() {
|
fn semversion_minor_inc() {
|
||||||
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_4", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -99,13 +95,12 @@ fn semversion_minor_inc() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn semversion_patch_inc() {
|
fn semversion_patch_inc() {
|
||||||
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_5", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -120,13 +115,12 @@ fn semversion_patch_inc() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn semversion_without_passing_field() {
|
fn semversion_without_passing_field() {
|
||||||
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
|
Playground::setup("plugin_inc_test_6", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
"#
|
"#,
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
mod helpers;
|
mod helpers;
|
||||||
|
|
||||||
use helpers as h;
|
|
||||||
use h::{Playground, Stub::*};
|
use h::{Playground, Stub::*};
|
||||||
|
use helpers as h;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_only_apply_one() {
|
fn can_only_apply_one() {
|
||||||
@ -10,9 +10,7 @@ fn can_only_apply_one() {
|
|||||||
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
|
"open caco3_plastics.csv | first 1 | str origin --downcase --upcase"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(
|
assert!(actual.contains("Usage: str field [--downcase|--upcase|--to-int"));
|
||||||
actual.contains("Usage: str field [--downcase|--upcase|--to-int|--replace|--find-replace]")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -39,8 +37,7 @@ fn acts_without_passing_field() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn downcases() {
|
fn downcases() {
|
||||||
Playground::setup("plugin_str_test_2", |dirs, sandbox| {
|
Playground::setup("plugin_str_test_2", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[dependency]
|
[dependency]
|
||||||
@ -60,8 +57,7 @@ fn downcases() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn upcases() {
|
fn upcases() {
|
||||||
Playground::setup("plugin_str_test_3", |dirs, sandbox| {
|
Playground::setup("plugin_str_test_3", |dirs, sandbox| {
|
||||||
sandbox
|
sandbox.with_files(vec![FileWithContent(
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
"sample.toml",
|
||||||
r#"
|
r#"
|
||||||
[package]
|
[package]
|
||||||
@ -94,81 +90,3 @@ fn converts_to_int() {
|
|||||||
|
|
||||||
assert_eq!(actual, "2509000000");
|
assert_eq!(actual, "2509000000");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn replaces() {
|
|
||||||
Playground::setup("plugin_str_test_4", |dirs, sandbox| {
|
|
||||||
sandbox
|
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "nushell"
|
|
||||||
"#,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
let actual = nu!(
|
|
||||||
cwd: dirs.test(), h::pipeline(
|
|
||||||
r#"
|
|
||||||
open sample.toml
|
|
||||||
| str package.name --replace wykittenshell
|
|
||||||
| get package.name
|
|
||||||
| echo $it
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual, "wykittenshell");
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn find_and_replaces() {
|
|
||||||
Playground::setup("plugin_str_test_5", |dirs, sandbox| {
|
|
||||||
sandbox
|
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
|
||||||
r#"
|
|
||||||
[fortune.teller]
|
|
||||||
phone = "1-800-KATZ"
|
|
||||||
"#,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
let actual = nu!(
|
|
||||||
cwd: dirs.test(), h::pipeline(
|
|
||||||
r#"
|
|
||||||
open sample.toml
|
|
||||||
| str fortune.teller.phone --find-replace KATZ "5289"
|
|
||||||
| get fortune.teller.phone
|
|
||||||
| echo $it
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual, "1-800-5289");
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn find_and_replaces_without_passing_field() {
|
|
||||||
Playground::setup("plugin_str_test_6", |dirs, sandbox| {
|
|
||||||
sandbox
|
|
||||||
.with_files(vec![FileWithContent(
|
|
||||||
"sample.toml",
|
|
||||||
r#"
|
|
||||||
[fortune.teller]
|
|
||||||
phone = "1-800-KATZ"
|
|
||||||
"#,
|
|
||||||
)]);
|
|
||||||
|
|
||||||
let actual = nu!(
|
|
||||||
cwd: dirs.test(), h::pipeline(
|
|
||||||
r#"
|
|
||||||
open sample.toml
|
|
||||||
| get fortune.teller.phone
|
|
||||||
| str --find-replace KATZ "5289"
|
|
||||||
| echo $it
|
|
||||||
"#
|
|
||||||
));
|
|
||||||
|
|
||||||
assert_eq!(actual, "1-800-5289");
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user