From 958bb534b4a08ba2beb14a36402a28772bb98ba5 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 6 Jul 2019 05:19:19 +1200 Subject: [PATCH] Finish moving a couple commands to plugins, remove unused plugin --- Cargo.lock | 7 ---- Cargo.toml | 13 +++----- src/cli.rs | 2 -- src/commands.rs | 2 -- src/commands/skip.rs | 32 ------------------- src/commands/tree.rs | 17 ---------- src/plugins/{newskip.rs => skip.rs} | 0 src/plugins/sum.rs | 48 ---------------------------- src/plugins/{treeview.rs => tree.rs} | 2 +- 9 files changed, 5 insertions(+), 118 deletions(-) delete mode 100644 src/commands/skip.rs delete mode 100644 src/commands/tree.rs rename src/plugins/{newskip.rs => skip.rs} (100%) delete mode 100644 src/plugins/sum.rs rename src/plugins/{treeview.rs => tree.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index 8ee077b3d4..646e8c1749 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1668,7 +1668,6 @@ dependencies = [ "rawkey 0.1.0 (git+https://github.com/jonathandturner/rawkey.git)", "regex 1.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)", - "resize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "roxmltree 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2394,11 +2393,6 @@ dependencies = [ "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "resize" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "result" version = "1.0.0" @@ -3614,7 +3608,6 @@ dependencies = [ "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum render-tree 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "68ed587df09cfb7ce1bc6fe8f77e24db219f222c049326ccbfb948ec67e31664" "checksum reqwest 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)" = "00eb63f212df0e358b427f0f40aa13aaea010b470be642ad422bcbca2feff2e4" -"checksum resize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ed16788c219e719ec11912d96f4e819641941578d1b02f00dab139b00789fb8" "checksum result 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" "checksum roxmltree 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "330d8f80a274bc3cb608908ee345970e7e24b96907f1ad69615a498bec57871c" "checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" diff --git a/Cargo.toml b/Cargo.toml index bc4e8f454f..ca82128bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,6 @@ regex = "1.1.8" pretty-hex = "0.1.0" neso = "0.5.0" rawkey = { git = "https://github.com/jonathandturner/rawkey.git" } -resize = "0.3.0" crossterm = "0.9.6" tempfile = "3.1.0" image = "0.21.2" @@ -79,21 +78,17 @@ pretty_assertions = "0.6.1" name = "nu" path = "src/lib.rs" -[[bin]] -name = "nu_plugin_sum" -path = "src/plugins/sum.rs" - [[bin]] name = "nu_plugin_inc" path = "src/plugins/inc.rs" [[bin]] -name = "nu_plugin_newskip" -path = "src/plugins/newskip.rs" +name = "nu_plugin_skip" +path = "src/plugins/skip.rs" [[bin]] -name = "nu_plugin_treeview" -path = "src/plugins/treeview.rs" +name = "nu_plugin_tree" +path = "src/plugins/tree.rs" [[bin]] name = "nu_plugin_binaryview" diff --git a/src/cli.rs b/src/cli.rs index be9bb01fb0..864462cd8b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -159,7 +159,6 @@ pub async fn cli() -> Result<(), Box> { command("sysinfo", Box::new(sysinfo::sysinfo)), command("cd", Box::new(cd::cd)), command("view", Box::new(view::view)), - command("skip", Box::new(skip::skip)), command("first", Box::new(first::first)), command("size", Box::new(size::size)), command("from-ini", Box::new(from_ini::from_ini)), @@ -193,7 +192,6 @@ pub async fn cli() -> Result<(), Box> { sink("clip", Box::new(clip::clip)), sink("save", Box::new(save::save)), sink("table", Box::new(table::table)), - sink("tree", Box::new(tree::tree)), sink("vtable", Box::new(vtable::vtable)), ]); } diff --git a/src/commands.rs b/src/commands.rs index db674c112b..551291fcfb 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -23,7 +23,6 @@ crate mod ps; crate mod reject; crate mod save; crate mod size; -crate mod skip; crate mod skip_while; crate mod sort_by; crate mod split_column; @@ -33,7 +32,6 @@ crate mod table; crate mod to_array; crate mod to_json; crate mod to_toml; -crate mod tree; crate mod trim; crate mod view; crate mod vtable; diff --git a/src/commands/skip.rs b/src/commands/skip.rs deleted file mode 100644 index 19b53ae582..0000000000 --- a/src/commands/skip.rs +++ /dev/null @@ -1,32 +0,0 @@ -use crate::errors::ShellError; -use crate::prelude::*; - -pub fn skip(args: CommandArgs) -> Result { - if args.len() == 0 { - return Err(ShellError::maybe_labeled_error( - "Skip requires an amount", - "needs parameter", - args.name_span, - )); - } - - let amount = args.expect_nth(0)?.as_i64(); - - let amount = match amount { - Ok(o) => o, - Err(_) => { - return Err(ShellError::labeled_error( - "Value is not a number", - "expected integer", - args.expect_nth(0)?.span, - )) - } - }; - - let input = args.input; - - Ok(input - .skip(amount as u64) - .map(|v| ReturnValue::Value(v)) - .boxed()) -} diff --git a/src/commands/tree.rs b/src/commands/tree.rs deleted file mode 100644 index c66ae596a0..0000000000 --- a/src/commands/tree.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::commands::command::SinkCommandArgs; -use crate::errors::ShellError; -use crate::format::TreeView; -use crate::prelude::*; - -pub fn tree(args: SinkCommandArgs) -> Result<(), ShellError> { - if args.input.len() > 0 { - let mut host = args.ctx.host.lock().unwrap(); - for i in args.input.iter() { - let view = TreeView::from_value(&i); - handle_unexpected(&mut *host, |host| crate::format::print_view(&view, host)); - host.stdout(""); - } - } - - Ok(()) -} diff --git a/src/plugins/newskip.rs b/src/plugins/skip.rs similarity index 100% rename from src/plugins/newskip.rs rename to src/plugins/skip.rs diff --git a/src/plugins/sum.rs b/src/plugins/sum.rs deleted file mode 100644 index f8ac4607a6..0000000000 --- a/src/plugins/sum.rs +++ /dev/null @@ -1,48 +0,0 @@ -use indexmap::IndexMap; -use nu::{serve_plugin, Args, CommandConfig, Plugin, Primitive, ShellError, Value}; - -struct Sum; - -impl Sum { - fn new() -> Sum { - Sum - } -} - -impl Plugin for Sum { - fn config(&mut self) -> Result { - Ok(CommandConfig { - name: "sum".to_string(), - mandatory_positional: vec![], - optional_positional: vec![], - can_load: vec![], - can_save: vec![], - is_filter: false, - is_sink: true, - named: IndexMap::new(), - rest_positional: true, - }) - } - - fn sink(&mut self, _args: Args, input: Vec) { - let mut total = 0i64; - - for v in input { - match v { - Value::Primitive(Primitive::Int(i)) => { - total += i; - } - Value::Primitive(Primitive::Bytes(i)) => { - total += i as i64; - } - _ => {} - } - } - - println!("Result: {}", total); - } -} - -fn main() { - serve_plugin(&mut Sum::new()); -} diff --git a/src/plugins/treeview.rs b/src/plugins/tree.rs similarity index 98% rename from src/plugins/treeview.rs rename to src/plugins/tree.rs index 0ff78dc998..a7a2da86a1 100644 --- a/src/plugins/treeview.rs +++ b/src/plugins/tree.rs @@ -84,7 +84,7 @@ struct TreeViewer; impl Plugin for TreeViewer { fn config(&mut self) -> Result { Ok(CommandConfig { - name: "treeview".to_string(), + name: "tree".to_string(), mandatory_positional: vec![], optional_positional: vec![], can_load: vec![],