nushell/src/commands/skip.rs

37 lines
928 B
Rust
Raw Normal View History

2019-05-16 04:42:44 +02:00
use crate::errors::ShellError;
use crate::prelude::*;
pub fn skip(args: CommandArgs) -> Result<OutputStream, ShellError> {
2019-06-08 00:35:07 +02:00
if args.positional.len() == 0 {
if let Some(span) = args.name_span {
return Err(ShellError::labeled_error(
"Skip requires an amount",
"needs parameter",
span,
));
} else {
return Err(ShellError::string("skip requires an amount."));
}
}
let amount = args.positional[0].as_i64();
let amount = match amount {
Ok(o) => o,
Err(_) => {
return Err(ShellError::labeled_error(
"Value is not a number",
"expected integer",
args.positional[0].span,
))
}
};
2019-05-16 04:42:44 +02:00
let input = args.input;
2019-05-16 04:42:44 +02:00
Ok(input
.skip(amount as u64)
2019-05-22 09:12:03 +02:00
.map(|v| ReturnValue::Value(v))
.boxed())
2019-05-16 04:42:44 +02:00
}