Finish moving a couple commands to plugins, remove unused plugin

This commit is contained in:
Jonathan Turner
2019-07-06 05:19:19 +12:00
parent 8c09337c04
commit 958bb534b4
9 changed files with 5 additions and 118 deletions

View File

@ -159,7 +159,6 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
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)),
]);
}

View File

@ -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;

View File

@ -1,32 +0,0 @@
use crate::errors::ShellError;
use crate::prelude::*;
pub fn skip(args: CommandArgs) -> Result<OutputStream, ShellError> {
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())
}

View File

@ -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(())
}

View File

@ -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<CommandConfig, ShellError> {
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<Value>) {
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());
}

View File

@ -84,7 +84,7 @@ struct TreeViewer;
impl Plugin for TreeViewer {
fn config(&mut self) -> Result<CommandConfig, ShellError> {
Ok(CommandConfig {
name: "treeview".to_string(),
name: "tree".to_string(),
mandatory_positional: vec![],
optional_positional: vec![],
can_load: vec![],