forked from extern/nushell
Fix warnings for Rust 1.51 (#3214)
* Fix warnings for Rust 1.51 * More fixes * More fixes
This commit is contained in:
parent
589fc0b8ad
commit
7e184b58b2
@ -15,7 +15,7 @@ fn main() {
|
|||||||
let g = (col * 255 / WIDTH) as u8;
|
let g = (col * 255 / WIDTH) as u8;
|
||||||
let b = 128;
|
let b = 128;
|
||||||
|
|
||||||
print!("{}", Style::default().on(Color::RGB(r, g, b)).paint(" "));
|
print!("{}", Style::default().on(Color::Rgb(r, g, b)).paint(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
|
@ -103,7 +103,7 @@ impl Color {
|
|||||||
Color::Cyan => write!(f, "36"),
|
Color::Cyan => write!(f, "36"),
|
||||||
Color::White => write!(f, "37"),
|
Color::White => write!(f, "37"),
|
||||||
Color::Fixed(num) => write!(f, "38;5;{}", &num),
|
Color::Fixed(num) => write!(f, "38;5;{}", &num),
|
||||||
Color::RGB(r, g, b) => write!(f, "38;2;{};{};{}", &r, &g, &b),
|
Color::Rgb(r, g, b) => write!(f, "38;2;{};{};{}", &r, &g, &b),
|
||||||
Color::DarkGray => write!(f, "90"),
|
Color::DarkGray => write!(f, "90"),
|
||||||
Color::LightRed => write!(f, "91"),
|
Color::LightRed => write!(f, "91"),
|
||||||
Color::LightGreen => write!(f, "92"),
|
Color::LightGreen => write!(f, "92"),
|
||||||
@ -128,7 +128,7 @@ impl Color {
|
|||||||
Color::Cyan => write!(f, "46"),
|
Color::Cyan => write!(f, "46"),
|
||||||
Color::White => write!(f, "47"),
|
Color::White => write!(f, "47"),
|
||||||
Color::Fixed(num) => write!(f, "48;5;{}", &num),
|
Color::Fixed(num) => write!(f, "48;5;{}", &num),
|
||||||
Color::RGB(r, g, b) => write!(f, "48;2;{};{};{}", &r, &g, &b),
|
Color::Rgb(r, g, b) => write!(f, "48;2;{};{};{}", &r, &g, &b),
|
||||||
Color::DarkGray => write!(f, "100"),
|
Color::DarkGray => write!(f, "100"),
|
||||||
Color::LightRed => write!(f, "101"),
|
Color::LightRed => write!(f, "101"),
|
||||||
Color::LightGreen => write!(f, "102"),
|
Color::LightGreen => write!(f, "102"),
|
||||||
@ -372,10 +372,10 @@ mod test {
|
|||||||
test!(fixed: Fixed(100); "hi" => "\x1B[38;5;100mhi\x1B[0m");
|
test!(fixed: Fixed(100); "hi" => "\x1B[38;5;100mhi\x1B[0m");
|
||||||
test!(fixed_on_purple: Fixed(100).on(Purple); "hi" => "\x1B[45;38;5;100mhi\x1B[0m");
|
test!(fixed_on_purple: Fixed(100).on(Purple); "hi" => "\x1B[45;38;5;100mhi\x1B[0m");
|
||||||
test!(fixed_on_fixed: Fixed(100).on(Fixed(200)); "hi" => "\x1B[48;5;200;38;5;100mhi\x1B[0m");
|
test!(fixed_on_fixed: Fixed(100).on(Fixed(200)); "hi" => "\x1B[48;5;200;38;5;100mhi\x1B[0m");
|
||||||
test!(rgb: RGB(70,130,180); "hi" => "\x1B[38;2;70;130;180mhi\x1B[0m");
|
test!(rgb: Rgb(70,130,180); "hi" => "\x1B[38;2;70;130;180mhi\x1B[0m");
|
||||||
test!(rgb_on_blue: RGB(70,130,180).on(Blue); "hi" => "\x1B[44;38;2;70;130;180mhi\x1B[0m");
|
test!(rgb_on_blue: Rgb(70,130,180).on(Blue); "hi" => "\x1B[44;38;2;70;130;180mhi\x1B[0m");
|
||||||
test!(blue_on_rgb: Blue.on(RGB(70,130,180)); "hi" => "\x1B[48;2;70;130;180;34mhi\x1B[0m");
|
test!(blue_on_rgb: Blue.on(Rgb(70,130,180)); "hi" => "\x1B[48;2;70;130;180;34mhi\x1B[0m");
|
||||||
test!(rgb_on_rgb: RGB(70,130,180).on(RGB(5,10,15)); "hi" => "\x1B[48;2;5;10;15;38;2;70;130;180mhi\x1B[0m");
|
test!(rgb_on_rgb: Rgb(70,130,180).on(Rgb(5,10,15)); "hi" => "\x1B[48;2;5;10;15;38;2;70;130;180mhi\x1B[0m");
|
||||||
test!(bold: Style::new().bold(); "hi" => "\x1B[1mhi\x1B[0m");
|
test!(bold: Style::new().bold(); "hi" => "\x1B[1mhi\x1B[0m");
|
||||||
test!(underline: Style::new().underline(); "hi" => "\x1B[4mhi\x1B[0m");
|
test!(underline: Style::new().underline(); "hi" => "\x1B[4mhi\x1B[0m");
|
||||||
test!(bunderline: Style::new().bold().underline(); "hi" => "\x1B[1;4mhi\x1B[0m");
|
test!(bunderline: Style::new().bold().underline(); "hi" => "\x1B[1;4mhi\x1B[0m");
|
||||||
|
@ -112,7 +112,7 @@ mod test {
|
|||||||
test!(both: style().bold().italic() => "Style { bold, italic }");
|
test!(both: style().bold().italic() => "Style { bold, italic }");
|
||||||
|
|
||||||
test!(red: Red.normal() => "Style { fg(Red) }");
|
test!(red: Red.normal() => "Style { fg(Red) }");
|
||||||
test!(redblue: Red.normal().on(RGB(3, 2, 4)) => "Style { fg(Red), on(RGB(3, 2, 4)) }");
|
test!(redblue: Red.normal().on(Rgb(3, 2, 4)) => "Style { fg(Red), on(Rgb(3, 2, 4)) }");
|
||||||
|
|
||||||
test!(everything:
|
test!(everything:
|
||||||
Red.on(Blue).blink().bold().dimmed().hidden().italic().reverse().strikethrough().underline() =>
|
Red.on(Blue).blink().bold().dimmed().hidden().italic().reverse().strikethrough().underline() =>
|
||||||
|
@ -11,7 +11,7 @@ use std::ops::Deref;
|
|||||||
/// display that string. `ANSIString` and `ANSIByteString` are aliases for
|
/// display that string. `ANSIString` and `ANSIByteString` are aliases for
|
||||||
/// this type on `str` and `\[u8]`, respectively.
|
/// this type on `str` and `\[u8]`, respectively.
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct ANSIGenericString<'a, S: 'a + ToOwned + ?Sized>
|
pub struct AnsiGenericString<'a, S: 'a + ToOwned + ?Sized>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
@ -30,12 +30,12 @@ where
|
|||||||
/// let clone_string = plain_string.clone();
|
/// let clone_string = plain_string.clone();
|
||||||
/// assert_eq!(clone_string, plain_string);
|
/// assert_eq!(clone_string, plain_string);
|
||||||
/// ```
|
/// ```
|
||||||
impl<'a, S: 'a + ToOwned + ?Sized> Clone for ANSIGenericString<'a, S>
|
impl<'a, S: 'a + ToOwned + ?Sized> Clone for AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
fn clone(&self) -> ANSIGenericString<'a, S> {
|
fn clone(&self) -> AnsiGenericString<'a, S> {
|
||||||
ANSIGenericString {
|
AnsiGenericString {
|
||||||
style: self.style,
|
style: self.style,
|
||||||
string: self.string.clone(),
|
string: self.string.clone(),
|
||||||
}
|
}
|
||||||
@ -85,26 +85,26 @@ where
|
|||||||
/// let plain_string = ANSIString::from("a plain string");
|
/// let plain_string = ANSIString::from("a plain string");
|
||||||
/// assert_eq!(&*plain_string, "a plain string");
|
/// assert_eq!(&*plain_string, "a plain string");
|
||||||
/// ```
|
/// ```
|
||||||
pub type ANSIString<'a> = ANSIGenericString<'a, str>;
|
pub type AnsiString<'a> = AnsiGenericString<'a, str>;
|
||||||
|
|
||||||
/// An `ANSIByteString` represents a formatted series of bytes. Use
|
/// An `AnsiByteString` represents a formatted series of bytes. Use
|
||||||
/// `ANSIByteString` when styling text with an unknown encoding.
|
/// `AnsiByteString` when styling text with an unknown encoding.
|
||||||
pub type ANSIByteString<'a> = ANSIGenericString<'a, [u8]>;
|
pub type AnsiByteString<'a> = AnsiGenericString<'a, [u8]>;
|
||||||
|
|
||||||
impl<'a, I, S: 'a + ToOwned + ?Sized> From<I> for ANSIGenericString<'a, S>
|
impl<'a, I, S: 'a + ToOwned + ?Sized> From<I> for AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
I: Into<Cow<'a, S>>,
|
I: Into<Cow<'a, S>>,
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
fn from(input: I) -> ANSIGenericString<'a, S> {
|
fn from(input: I) -> AnsiGenericString<'a, S> {
|
||||||
ANSIGenericString {
|
AnsiGenericString {
|
||||||
string: input.into(),
|
string: input.into(),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: 'a + ToOwned + ?Sized> ANSIGenericString<'a, S>
|
impl<'a, S: 'a + ToOwned + ?Sized> AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
@ -119,7 +119,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: 'a + ToOwned + ?Sized> Deref for ANSIGenericString<'a, S>
|
impl<'a, S: 'a + ToOwned + ?Sized> Deref for AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
@ -130,32 +130,32 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of `ANSIGenericString`s collected together, in order to be
|
/// A set of `AnsiGenericStrings`s collected together, in order to be
|
||||||
/// written with a minimum of control characters.
|
/// written with a minimum of control characters.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct ANSIGenericStrings<'a, S: 'a + ToOwned + ?Sized>(pub &'a [ANSIGenericString<'a, S>])
|
pub struct AnsiGenericStrings<'a, S: 'a + ToOwned + ?Sized>(pub &'a [AnsiGenericString<'a, S>])
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
S: PartialEq;
|
S: PartialEq;
|
||||||
|
|
||||||
/// A set of `ANSIString`s collected together, in order to be written with a
|
/// A set of `AnsiString`s collected together, in order to be written with a
|
||||||
/// minimum of control characters.
|
/// minimum of control characters.
|
||||||
pub type ANSIStrings<'a> = ANSIGenericStrings<'a, str>;
|
pub type AnsiStrings<'a> = AnsiGenericStrings<'a, str>;
|
||||||
|
|
||||||
/// A function to construct an `ANSIStrings` instance.
|
/// A function to construct an `AnsiStrings` instance.
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn ANSIStrings<'a>(arg: &'a [ANSIString<'a>]) -> ANSIStrings<'a> {
|
pub fn AnsiStrings<'a>(arg: &'a [AnsiString<'a>]) -> AnsiStrings<'a> {
|
||||||
ANSIGenericStrings(arg)
|
AnsiGenericStrings(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of `ANSIByteString`s collected together, in order to be
|
/// A set of `AnsiByteString`s collected together, in order to be
|
||||||
/// written with a minimum of control characters.
|
/// written with a minimum of control characters.
|
||||||
pub type ANSIByteStrings<'a> = ANSIGenericStrings<'a, [u8]>;
|
pub type AnsiByteStrings<'a> = AnsiGenericStrings<'a, [u8]>;
|
||||||
|
|
||||||
/// A function to construct an `ANSIByteStrings` instance.
|
/// A function to construct an `ANSIByteStrings` instance.
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn ANSIByteStrings<'a>(arg: &'a [ANSIByteString<'a>]) -> ANSIByteStrings<'a> {
|
pub fn ANSIByteStrings<'a>(arg: &'a [AnsiByteString<'a>]) -> AnsiByteStrings<'a> {
|
||||||
ANSIGenericStrings(arg)
|
AnsiGenericStrings(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- paint functions ----
|
// ---- paint functions ----
|
||||||
@ -163,12 +163,12 @@ pub fn ANSIByteStrings<'a>(arg: &'a [ANSIByteString<'a>]) -> ANSIByteStrings<'a>
|
|||||||
impl Style {
|
impl Style {
|
||||||
/// Paints the given text with this color, returning an ANSI string.
|
/// Paints the given text with this color, returning an ANSI string.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>(self, input: I) -> ANSIGenericString<'a, S>
|
pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>(self, input: I) -> AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
I: Into<Cow<'a, S>>,
|
I: Into<Cow<'a, S>>,
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
ANSIGenericString {
|
AnsiGenericString {
|
||||||
string: input.into(),
|
string: input.into(),
|
||||||
style: self,
|
style: self,
|
||||||
}
|
}
|
||||||
@ -185,12 +185,12 @@ impl Color {
|
|||||||
/// println!("{}", Blue.paint("da ba dee"));
|
/// println!("{}", Blue.paint("da ba dee"));
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>(self, input: I) -> ANSIGenericString<'a, S>
|
pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>(self, input: I) -> AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
I: Into<Cow<'a, S>>,
|
I: Into<Cow<'a, S>>,
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
{
|
{
|
||||||
ANSIGenericString {
|
AnsiGenericString {
|
||||||
string: input.into(),
|
string: input.into(),
|
||||||
style: self.normal(),
|
style: self.normal(),
|
||||||
}
|
}
|
||||||
@ -199,14 +199,14 @@ impl Color {
|
|||||||
|
|
||||||
// ---- writers for individual ANSI strings ----
|
// ---- writers for individual ANSI strings ----
|
||||||
|
|
||||||
impl<'a> fmt::Display for ANSIString<'a> {
|
impl<'a> fmt::Display for AnsiString<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let w: &mut dyn fmt::Write = f;
|
let w: &mut dyn fmt::Write = f;
|
||||||
self.write_to_any(w)
|
self.write_to_any(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ANSIByteString<'a> {
|
impl<'a> AnsiByteString<'a> {
|
||||||
/// Write an `ANSIByteString` to an `io::Write`. This writes the escape
|
/// Write an `ANSIByteString` to an `io::Write`. This writes the escape
|
||||||
/// sequences for the associated `Style` around the bytes.
|
/// sequences for the associated `Style` around the bytes.
|
||||||
pub fn write_to<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
|
pub fn write_to<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
@ -215,7 +215,7 @@ impl<'a> ANSIByteString<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: 'a + ToOwned + ?Sized> ANSIGenericString<'a, S>
|
impl<'a, S: 'a + ToOwned + ?Sized> AnsiGenericString<'a, S>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
&'a S: AsRef<[u8]>,
|
&'a S: AsRef<[u8]>,
|
||||||
@ -229,14 +229,14 @@ where
|
|||||||
|
|
||||||
// ---- writers for combined ANSI strings ----
|
// ---- writers for combined ANSI strings ----
|
||||||
|
|
||||||
impl<'a> fmt::Display for ANSIStrings<'a> {
|
impl<'a> fmt::Display for AnsiStrings<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let f: &mut dyn fmt::Write = f;
|
let f: &mut dyn fmt::Write = f;
|
||||||
self.write_to_any(f)
|
self.write_to_any(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ANSIByteStrings<'a> {
|
impl<'a> AnsiByteStrings<'a> {
|
||||||
/// Write `ANSIByteStrings` to an `io::Write`. This writes the minimal
|
/// Write `ANSIByteStrings` to an `io::Write`. This writes the minimal
|
||||||
/// escape sequences for the associated `Style`s around each set of
|
/// escape sequences for the associated `Style`s around each set of
|
||||||
/// bytes.
|
/// bytes.
|
||||||
@ -246,7 +246,7 @@ impl<'a> ANSIByteStrings<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: 'a + ToOwned + ?Sized + PartialEq> ANSIGenericStrings<'a, S>
|
impl<'a, S: 'a + ToOwned + ?Sized + PartialEq> AnsiGenericStrings<'a, S>
|
||||||
where
|
where
|
||||||
<S as ToOwned>::Owned: fmt::Debug,
|
<S as ToOwned>::Owned: fmt::Debug,
|
||||||
&'a S: AsRef<[u8]>,
|
&'a S: AsRef<[u8]>,
|
||||||
@ -289,7 +289,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
pub use super::super::ANSIStrings;
|
pub use super::super::AnsiStrings;
|
||||||
pub use crate::style::Color::*;
|
pub use crate::style::Color::*;
|
||||||
pub use crate::style::Style;
|
pub use crate::style::Style;
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ mod tests {
|
|||||||
fn no_control_codes_for_plain() {
|
fn no_control_codes_for_plain() {
|
||||||
let one = Style::default().paint("one");
|
let one = Style::default().paint("one");
|
||||||
let two = Style::default().paint("two");
|
let two = Style::default().paint("two");
|
||||||
let output = format!("{}", ANSIStrings(&[one, two]));
|
let output = format!("{}", AnsiStrings(&[one, two]));
|
||||||
assert_eq!(&*output, "onetwo");
|
assert_eq!(&*output, "onetwo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ pub enum Color {
|
|||||||
Fixed(u8),
|
Fixed(u8),
|
||||||
|
|
||||||
/// A 24-bit RGB color, as specified by ISO-8613-3.
|
/// A 24-bit RGB color, as specified by ISO-8613-3.
|
||||||
RGB(u8, u8, u8),
|
Rgb(u8, u8, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::display::{ANSIString, ANSIStrings};
|
use crate::display::{AnsiString, AnsiStrings};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// Return a substring of the given ANSIStrings sequence, while keeping the formatting.
|
/// Return a substring of the given ANSIStrings sequence, while keeping the formatting.
|
||||||
pub fn sub_string<'a>(
|
pub fn sub_string<'a>(
|
||||||
start: usize,
|
start: usize,
|
||||||
len: usize,
|
len: usize,
|
||||||
strs: &ANSIStrings<'a>,
|
strs: &AnsiStrings<'a>,
|
||||||
) -> Vec<ANSIString<'static>> {
|
) -> Vec<AnsiString<'static>> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
let mut pos = start;
|
let mut pos = start;
|
||||||
let mut len_rem = len;
|
let mut len_rem = len;
|
||||||
@ -39,7 +39,7 @@ pub fn sub_string<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return a concatenated copy of `strs` without the formatting, as an allocated `String`.
|
/// Return a concatenated copy of `strs` without the formatting, as an allocated `String`.
|
||||||
pub fn unstyle(strs: &ANSIStrings) -> String {
|
pub fn unstyle(strs: &AnsiStrings) -> String {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
|
|
||||||
for i in strs.0.iter() {
|
for i in strs.0.iter() {
|
||||||
@ -50,7 +50,7 @@ pub fn unstyle(strs: &ANSIStrings) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the unstyled length of ANSIStrings. This is equaivalent to `unstyle(strs).len()`.
|
/// Return the unstyled length of ANSIStrings. This is equaivalent to `unstyle(strs).len()`.
|
||||||
pub fn unstyled_len(strs: &ANSIStrings) -> usize {
|
pub fn unstyled_len(strs: &AnsiStrings) -> usize {
|
||||||
let mut l = 0;
|
let mut l = 0;
|
||||||
for i in strs.0.iter() {
|
for i in strs.0.iter() {
|
||||||
l += i.deref().len();
|
l += i.deref().len();
|
||||||
@ -70,7 +70,7 @@ mod test {
|
|||||||
Red.paint("-second"),
|
Red.paint("-second"),
|
||||||
White.paint("-third"),
|
White.paint("-third"),
|
||||||
];
|
];
|
||||||
let a = ANSIStrings(&l);
|
let a = AnsiStrings(&l);
|
||||||
assert_eq!(unstyle(&a), "first-second-third");
|
assert_eq!(unstyle(&a), "first-second-third");
|
||||||
assert_eq!(unstyled_len(&a), 18);
|
assert_eq!(unstyled_len(&a), 18);
|
||||||
|
|
||||||
|
@ -184,21 +184,21 @@ pub(crate) use first::First;
|
|||||||
pub(crate) use flatten::Command as Flatten;
|
pub(crate) use flatten::Command as Flatten;
|
||||||
pub(crate) use format::{FileSize, Format};
|
pub(crate) use format::{FileSize, Format};
|
||||||
pub(crate) use from::From;
|
pub(crate) use from::From;
|
||||||
pub(crate) use from_csv::FromCSV;
|
pub(crate) use from_csv::FromCsv;
|
||||||
pub(crate) use from_eml::FromEML;
|
pub(crate) use from_eml::FromEml;
|
||||||
pub(crate) use from_ics::FromIcs;
|
pub(crate) use from_ics::FromIcs;
|
||||||
pub(crate) use from_ini::FromINI;
|
pub(crate) use from_ini::FromIni;
|
||||||
pub(crate) use from_json::FromJSON;
|
pub(crate) use from_json::FromJson;
|
||||||
pub(crate) use from_ods::FromODS;
|
pub(crate) use from_ods::FromOds;
|
||||||
pub(crate) use from_ssv::FromSSV;
|
pub(crate) use from_ssv::FromSsv;
|
||||||
pub(crate) use from_toml::FromTOML;
|
pub(crate) use from_toml::FromToml;
|
||||||
pub(crate) use from_tsv::FromTSV;
|
pub(crate) use from_tsv::FromTsv;
|
||||||
pub(crate) use from_url::FromURL;
|
pub(crate) use from_url::FromUrl;
|
||||||
pub(crate) use from_vcf::FromVcf;
|
pub(crate) use from_vcf::FromVcf;
|
||||||
pub(crate) use from_xlsx::FromXLSX;
|
pub(crate) use from_xlsx::FromXlsx;
|
||||||
pub(crate) use from_xml::FromXML;
|
pub(crate) use from_xml::FromXml;
|
||||||
pub(crate) use from_yaml::FromYAML;
|
pub(crate) use from_yaml::FromYaml;
|
||||||
pub(crate) use from_yaml::FromYML;
|
pub(crate) use from_yaml::FromYml;
|
||||||
pub(crate) use get::Command as Get;
|
pub(crate) use get::Command as Get;
|
||||||
pub(crate) use group_by::Command as GroupBy;
|
pub(crate) use group_by::Command as GroupBy;
|
||||||
pub(crate) use group_by_date::GroupByDate;
|
pub(crate) use group_by_date::GroupByDate;
|
||||||
@ -272,15 +272,15 @@ pub(crate) use table::Table;
|
|||||||
pub(crate) use tags::Tags;
|
pub(crate) use tags::Tags;
|
||||||
pub(crate) use termsize::TermSize;
|
pub(crate) use termsize::TermSize;
|
||||||
pub(crate) use to::To;
|
pub(crate) use to::To;
|
||||||
pub(crate) use to_csv::ToCSV;
|
pub(crate) use to_csv::ToCsv;
|
||||||
pub(crate) use to_html::ToHTML;
|
pub(crate) use to_html::ToHtml;
|
||||||
pub(crate) use to_json::ToJSON;
|
pub(crate) use to_json::ToJson;
|
||||||
pub(crate) use to_md::Command as ToMarkdown;
|
pub(crate) use to_md::Command as ToMarkdown;
|
||||||
pub(crate) use to_toml::ToTOML;
|
pub(crate) use to_toml::ToToml;
|
||||||
pub(crate) use to_tsv::ToTSV;
|
pub(crate) use to_tsv::ToTsv;
|
||||||
pub(crate) use to_url::ToURL;
|
pub(crate) use to_url::ToUrl;
|
||||||
pub(crate) use to_xml::ToXML;
|
pub(crate) use to_xml::ToXml;
|
||||||
pub(crate) use to_yaml::ToYAML;
|
pub(crate) use to_yaml::ToYaml;
|
||||||
pub(crate) use touch::Touch;
|
pub(crate) use touch::Touch;
|
||||||
pub(crate) use uniq::Uniq;
|
pub(crate) use uniq::Uniq;
|
||||||
pub(crate) use url_::{UrlCommand, UrlHost, UrlPath, UrlQuery, UrlScheme};
|
pub(crate) use url_::{UrlCommand, UrlHost, UrlPath, UrlQuery, UrlScheme};
|
||||||
|
@ -190,30 +190,30 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
|
|||||||
whole_stream_command(MathCeil),
|
whole_stream_command(MathCeil),
|
||||||
// File format output
|
// File format output
|
||||||
whole_stream_command(To),
|
whole_stream_command(To),
|
||||||
whole_stream_command(ToCSV),
|
whole_stream_command(ToCsv),
|
||||||
whole_stream_command(ToHTML),
|
whole_stream_command(ToHtml),
|
||||||
whole_stream_command(ToJSON),
|
whole_stream_command(ToJson),
|
||||||
whole_stream_command(ToMarkdown),
|
whole_stream_command(ToMarkdown),
|
||||||
whole_stream_command(ToTOML),
|
whole_stream_command(ToToml),
|
||||||
whole_stream_command(ToTSV),
|
whole_stream_command(ToTsv),
|
||||||
whole_stream_command(ToURL),
|
whole_stream_command(ToUrl),
|
||||||
whole_stream_command(ToYAML),
|
whole_stream_command(ToYaml),
|
||||||
whole_stream_command(ToXML),
|
whole_stream_command(ToXml),
|
||||||
// File format input
|
// File format input
|
||||||
whole_stream_command(From),
|
whole_stream_command(From),
|
||||||
whole_stream_command(FromCSV),
|
whole_stream_command(FromCsv),
|
||||||
whole_stream_command(FromEML),
|
whole_stream_command(FromEml),
|
||||||
whole_stream_command(FromTSV),
|
whole_stream_command(FromTsv),
|
||||||
whole_stream_command(FromSSV),
|
whole_stream_command(FromSsv),
|
||||||
whole_stream_command(FromINI),
|
whole_stream_command(FromIni),
|
||||||
whole_stream_command(FromJSON),
|
whole_stream_command(FromJson),
|
||||||
whole_stream_command(FromODS),
|
whole_stream_command(FromOds),
|
||||||
whole_stream_command(FromTOML),
|
whole_stream_command(FromToml),
|
||||||
whole_stream_command(FromURL),
|
whole_stream_command(FromUrl),
|
||||||
whole_stream_command(FromXLSX),
|
whole_stream_command(FromXlsx),
|
||||||
whole_stream_command(FromXML),
|
whole_stream_command(FromXml),
|
||||||
whole_stream_command(FromYAML),
|
whole_stream_command(FromYaml),
|
||||||
whole_stream_command(FromYML),
|
whole_stream_command(FromYml),
|
||||||
whole_stream_command(FromIcs),
|
whole_stream_command(FromIcs),
|
||||||
whole_stream_command(FromVcf),
|
whole_stream_command(FromVcf),
|
||||||
// "Private" commands (not intended to be accessed directly)
|
// "Private" commands (not intended to be accessed directly)
|
||||||
|
@ -4,16 +4,16 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromCSV;
|
pub struct FromCsv;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromCSVArgs {
|
pub struct FromCsvArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
separator: Option<Value>,
|
separator: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromCSV {
|
impl WholeStreamCommand for FromCsv {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from csv"
|
"from csv"
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ async fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
FromCSVArgs {
|
FromCsvArgs {
|
||||||
noheaders,
|
noheaders,
|
||||||
separator,
|
separator,
|
||||||
},
|
},
|
||||||
@ -105,13 +105,13 @@ async fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromCSV;
|
use super::FromCsv;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromCSV {})
|
test_examples(FromCsv {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,18 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue};
|
use nu_protocol::{ReturnSuccess, Signature, SyntaxShape, TaggedDictBuilder, UntaggedValue};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct FromEML;
|
pub struct FromEml;
|
||||||
|
|
||||||
const DEFAULT_BODY_PREVIEW: usize = 50;
|
const DEFAULT_BODY_PREVIEW: usize = 50;
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct FromEMLArgs {
|
pub struct FromEmlArgs {
|
||||||
#[serde(rename(deserialize = "preview-body"))]
|
#[serde(rename(deserialize = "preview-body"))]
|
||||||
preview_body: Option<Tagged<usize>>,
|
preview_body: Option<Tagged<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromEML {
|
impl WholeStreamCommand for FromEml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from eml"
|
"from eml"
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ fn headerfieldvalue_to_value(tag: &Tag, value: &HeaderFieldValue) -> UntaggedVal
|
|||||||
|
|
||||||
async fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let (eml_args, input): (FromEMLArgs, _) = args.process().await?;
|
let (eml_args, input): (FromEmlArgs, _) = args.process().await?;
|
||||||
let value = input.collect_string(tag.clone()).await?;
|
let value = input.collect_string(tag.clone()).await?;
|
||||||
|
|
||||||
let body_preview = eml_args
|
let body_preview = eml_args
|
||||||
@ -121,13 +121,13 @@ async fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromEML;
|
use super::FromEml;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromEML {})
|
test_examples(FromEml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{Primitive, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Primitive, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct FromINI;
|
pub struct FromIni;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromINI {
|
impl WholeStreamCommand for FromIni {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from ini"
|
"from ini"
|
||||||
}
|
}
|
||||||
@ -86,13 +86,13 @@ async fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromINI;
|
use super::FromIni;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromINI {})
|
test_examples(FromIni {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,15 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromJSON;
|
pub struct FromJson;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromJSONArgs {
|
pub struct FromJsonArgs {
|
||||||
objects: bool,
|
objects: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromJSON {
|
impl WholeStreamCommand for FromJson {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from json"
|
"from json"
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ pub fn from_json_string_to_value(s: String, tag: impl Into<Tag>) -> nu_json::Res
|
|||||||
async fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let (FromJSONArgs { objects }, input) = args.process().await?;
|
let (FromJsonArgs { objects }, input) = args.process().await?;
|
||||||
let concat_string = input.collect_string(name_tag.clone()).await?;
|
let concat_string = input.collect_string(name_tag.clone()).await?;
|
||||||
|
|
||||||
let string_clone: Vec<_> = concat_string.item.lines().map(|x| x.to_string()).collect();
|
let string_clone: Vec<_> = concat_string.item.lines().map(|x| x.to_string()).collect();
|
||||||
@ -135,13 +135,13 @@ async fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromJSON;
|
use super::FromJson;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromJSON {})
|
test_examples(FromJson {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
pub struct FromODS;
|
pub struct FromOds;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromODSArgs {
|
pub struct FromOdsArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromODS {
|
impl WholeStreamCommand for FromOds {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from ods"
|
"from ods"
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ async fn from_ods(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let span = tag.span;
|
let span = tag.span;
|
||||||
|
|
||||||
let (
|
let (
|
||||||
FromODSArgs {
|
FromOdsArgs {
|
||||||
noheaders: _noheaders,
|
noheaders: _noheaders,
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
@ -93,13 +93,13 @@ async fn from_ods(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromODS;
|
use super::FromOds;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromODS {})
|
test_examples(FromOds {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
use nu_source::Tagged;
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct FromSSV;
|
pub struct FromSsv;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromSSVArgs {
|
pub struct FromSsvArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
#[serde(rename(deserialize = "aligned-columns"))]
|
#[serde(rename(deserialize = "aligned-columns"))]
|
||||||
aligned_columns: bool,
|
aligned_columns: bool,
|
||||||
@ -21,7 +21,7 @@ const STRING_REPRESENTATION: &str = "from ssv";
|
|||||||
const DEFAULT_MINIMUM_SPACES: usize = 2;
|
const DEFAULT_MINIMUM_SPACES: usize = 2;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromSSV {
|
impl WholeStreamCommand for FromSsv {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
STRING_REPRESENTATION
|
STRING_REPRESENTATION
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ fn from_ssv_string_to_value(
|
|||||||
async fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let (
|
let (
|
||||||
FromSSVArgs {
|
FromSsvArgs {
|
||||||
noheaders,
|
noheaders,
|
||||||
aligned_columns,
|
aligned_columns,
|
||||||
minimum_spaces,
|
minimum_spaces,
|
||||||
@ -489,9 +489,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use super::FromSSV;
|
use super::FromSsv;
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromSSV {})
|
test_examples(FromSsv {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromTOML;
|
pub struct FromToml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromTOML {
|
impl WholeStreamCommand for FromToml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from toml"
|
"from toml"
|
||||||
}
|
}
|
||||||
@ -92,13 +92,13 @@ pub async fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromTOML;
|
use super::FromToml;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromTOML {})
|
test_examples(FromToml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,15 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::Signature;
|
||||||
|
|
||||||
pub struct FromTSV;
|
pub struct FromTsv;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromTSVArgs {
|
pub struct FromTsvArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromTSV {
|
impl WholeStreamCommand for FromTsv {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from tsv"
|
"from tsv"
|
||||||
}
|
}
|
||||||
@ -36,20 +36,20 @@ impl WholeStreamCommand for FromTSV {
|
|||||||
|
|
||||||
async fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let (FromTSVArgs { noheaders }, input) = args.process().await?;
|
let (FromTsvArgs { noheaders }, input) = args.process().await?;
|
||||||
|
|
||||||
from_delimited_data(noheaders, '\t', "TSV", input, name).await
|
from_delimited_data(noheaders, '\t', "TSV", input, name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromTSV;
|
use super::FromTsv;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromTSV {})
|
test_examples(FromTsv {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
||||||
|
|
||||||
pub struct FromURL;
|
pub struct FromUrl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromURL {
|
impl WholeStreamCommand for FromUrl {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from url"
|
"from url"
|
||||||
}
|
}
|
||||||
@ -55,13 +55,13 @@ async fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromURL;
|
use super::FromUrl;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromURL {})
|
test_examples(FromUrl {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ use nu_errors::ShellError;
|
|||||||
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
use nu_protocol::{ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
pub struct FromXLSX;
|
pub struct FromXlsx;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FromXLSXArgs {
|
pub struct FromXlsxArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromXLSX {
|
impl WholeStreamCommand for FromXlsx {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from xlsx"
|
"from xlsx"
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ async fn from_xlsx(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let span = tag.span;
|
let span = tag.span;
|
||||||
let (
|
let (
|
||||||
FromXLSXArgs {
|
FromXlsxArgs {
|
||||||
noheaders: _noheaders,
|
noheaders: _noheaders,
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
@ -93,13 +93,13 @@ async fn from_xlsx(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::FromXLSX;
|
use super::FromXlsx;
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromXLSX {})
|
test_examples(FromXlsx {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromXML;
|
pub struct FromXml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromXML {
|
impl WholeStreamCommand for FromXml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from xml"
|
"from xml"
|
||||||
}
|
}
|
||||||
@ -298,9 +298,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use super::FromXML;
|
use super::FromXml;
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromXML {})
|
test_examples(FromXml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{Primitive, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct FromYAML;
|
pub struct FromYaml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromYAML {
|
impl WholeStreamCommand for FromYaml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from yaml"
|
"from yaml"
|
||||||
}
|
}
|
||||||
@ -24,10 +24,10 @@ impl WholeStreamCommand for FromYAML {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FromYML;
|
pub struct FromYml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for FromYML {
|
impl WholeStreamCommand for FromYml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"from yml"
|
"from yml"
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ mod tests {
|
|||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(FromYAML {})
|
test_examples(FromYaml {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,16 +4,16 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct ToCSV;
|
pub struct ToCsv;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToCSVArgs {
|
pub struct ToCsvArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
separator: Option<Value>,
|
separator: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToCSV {
|
impl WholeStreamCommand for ToCsv {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to csv"
|
"to csv"
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ impl WholeStreamCommand for ToCSV {
|
|||||||
async fn to_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn to_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let (
|
let (
|
||||||
ToCSVArgs {
|
ToCsvArgs {
|
||||||
separator,
|
separator,
|
||||||
noheaders,
|
noheaders,
|
||||||
},
|
},
|
||||||
@ -80,12 +80,12 @@ async fn to_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToCSV;
|
use super::ToCsv;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToCSV {})
|
test_examples(ToCsv {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ impl Default for HtmlTheme {
|
|||||||
#[folder = "assets/"]
|
#[folder = "assets/"]
|
||||||
struct Assets;
|
struct Assets;
|
||||||
|
|
||||||
pub struct ToHTML;
|
pub struct ToHtml;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToHTMLArgs {
|
pub struct ToHtmlArgs {
|
||||||
html_color: bool,
|
html_color: bool,
|
||||||
no_color: bool,
|
no_color: bool,
|
||||||
dark: bool,
|
dark: bool,
|
||||||
@ -92,7 +92,7 @@ pub struct ToHTMLArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToHTML {
|
impl WholeStreamCommand for ToHtml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to html"
|
"to html"
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ fn get_list_of_theme_names() -> Vec<String> {
|
|||||||
async fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn to_html(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
let (
|
let (
|
||||||
ToHTMLArgs {
|
ToHtmlArgs {
|
||||||
html_color,
|
html_color,
|
||||||
no_color,
|
no_color,
|
||||||
dark,
|
dark,
|
||||||
@ -758,6 +758,6 @@ mod tests {
|
|||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToHTML {})
|
test_examples(ToHtml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,15 @@ use nu_protocol::{
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
pub struct ToJSON;
|
pub struct ToJson;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToJSONArgs {
|
pub struct ToJsonArgs {
|
||||||
pretty: Option<Value>,
|
pretty: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToJSON {
|
impl WholeStreamCommand for ToJson {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to json"
|
"to json"
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ fn json_list(input: &[Value]) -> Result<Vec<serde_json::Value>, ShellError> {
|
|||||||
|
|
||||||
async fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
let (ToJSONArgs { pretty }, input) = args.process().await?;
|
let (ToJsonArgs { pretty }, input) = args.process().await?;
|
||||||
let name_span = name_tag.span;
|
let name_span = name_tag.span;
|
||||||
let input: Vec<Value> = input.collect().await;
|
let input: Vec<Value> = input.collect().await;
|
||||||
|
|
||||||
@ -256,12 +256,12 @@ async fn to_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToJSON;
|
use super::ToJson;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToJSON {})
|
test_examples(ToJson {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::{CoerceInto, ShellError};
|
use nu_errors::{CoerceInto, ShellError};
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UnspannedPathMember, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, UnspannedPathMember, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct ToTOML;
|
pub struct ToToml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToTOML {
|
impl WholeStreamCommand for ToToml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to toml"
|
"to toml"
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ mod tests {
|
|||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToTOML {})
|
test_examples(ToToml {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,15 +4,15 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::Signature;
|
||||||
|
|
||||||
pub struct ToTSV;
|
pub struct ToTsv;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToTSVArgs {
|
pub struct ToTsvArgs {
|
||||||
noheaders: bool,
|
noheaders: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToTSV {
|
impl WholeStreamCommand for ToTsv {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to tsv"
|
"to tsv"
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ impl WholeStreamCommand for ToTSV {
|
|||||||
|
|
||||||
async fn to_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn to_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let (ToTSVArgs { noheaders }, input) = args.process().await?;
|
let (ToTsvArgs { noheaders }, input) = args.process().await?;
|
||||||
|
|
||||||
to_delimited_data(noheaders, '\t', "TSV", input, name).await
|
to_delimited_data(noheaders, '\t', "TSV", input, name).await
|
||||||
}
|
}
|
||||||
@ -44,12 +44,12 @@ async fn to_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToTSV;
|
use super::ToTsv;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToTSV {})
|
test_examples(ToTsv {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct ToURL;
|
pub struct ToUrl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToURL {
|
impl WholeStreamCommand for ToUrl {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to url"
|
"to url"
|
||||||
}
|
}
|
||||||
@ -76,12 +76,12 @@ async fn to_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToURL;
|
use super::ToUrl;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToURL {})
|
test_examples(ToUrl {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,15 @@ use std::collections::HashSet;
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
pub struct ToXML;
|
pub struct ToXml;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToXMLArgs {
|
pub struct ToXmlArgs {
|
||||||
pretty: Option<Value>,
|
pretty: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToXML {
|
impl WholeStreamCommand for ToXml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to xml"
|
"to xml"
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ pub fn write_xml_events<W: Write>(
|
|||||||
async fn to_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
async fn to_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
let name_span = name_tag.span;
|
let name_span = name_tag.span;
|
||||||
let (ToXMLArgs { pretty }, input) = args.process().await?;
|
let (ToXmlArgs { pretty }, input) = args.process().await?;
|
||||||
let input: Vec<Value> = input.collect().await;
|
let input: Vec<Value> = input.collect().await;
|
||||||
|
|
||||||
let to_process_input = match input.len() {
|
let to_process_input = match input.len() {
|
||||||
@ -189,12 +189,12 @@ async fn to_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToXML;
|
use super::ToXml;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToXML {})
|
test_examples(ToXml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ use nu_engine::WholeStreamCommand;
|
|||||||
use nu_errors::{CoerceInto, ShellError};
|
use nu_errors::{CoerceInto, ShellError};
|
||||||
use nu_protocol::{Primitive, ReturnSuccess, Signature, UnspannedPathMember, UntaggedValue, Value};
|
use nu_protocol::{Primitive, ReturnSuccess, Signature, UnspannedPathMember, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct ToYAML;
|
pub struct ToYaml;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl WholeStreamCommand for ToYAML {
|
impl WholeStreamCommand for ToYaml {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to yaml"
|
"to yaml"
|
||||||
}
|
}
|
||||||
@ -164,12 +164,12 @@ async fn to_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ShellError;
|
use super::ShellError;
|
||||||
use super::ToYAML;
|
use super::ToYaml;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||||
use crate::examples::test as test_examples;
|
use crate::examples::test as test_examples;
|
||||||
|
|
||||||
test_examples(ToYAML {})
|
test_examples(ToYaml {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,24 +151,12 @@ fn errors_fetching_by_column_not_present() {
|
|||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("Unknown column"),);
|
||||||
actual.err.contains("Unknown column"),
|
assert!(actual.err.contains("There isn't a column named 'taco'"),);
|
||||||
format!("actual: {:?}", actual.err)
|
assert!(actual.err.contains("Perhaps you meant 'taconushell'?"),);
|
||||||
);
|
assert!(actual
|
||||||
assert!(
|
|
||||||
actual.err.contains("There isn't a column named 'taco'"),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual.err.contains("Perhaps you meant 'taconushell'?"),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual
|
|
||||||
.err
|
.err
|
||||||
.contains("Columns available: pizzanushell, taconushell"),
|
.contains("Columns available: pizzanushell, taconushell"),);
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,20 +179,11 @@ fn errors_fetching_by_column_using_a_number() {
|
|||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("No rows available"),);
|
||||||
actual.err.contains("No rows available"),
|
assert!(actual.err.contains("A row at '0' can't be indexed."),);
|
||||||
format!("actual: {:?}", actual.err)
|
assert!(actual
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual.err.contains("A row at '0' can't be indexed."),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual
|
|
||||||
.err
|
.err
|
||||||
.contains("Appears to contain columns. Columns available: 0"),
|
.contains("Appears to contain columns. Columns available: 0"),)
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
@ -226,18 +205,9 @@ fn errors_fetching_by_index_out_of_bounds() {
|
|||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("Row not found"),);
|
||||||
actual.err.contains("Row not found"),
|
assert!(actual.err.contains("There isn't a row indexed at 3"),);
|
||||||
format!("actual: {:?}", actual.err)
|
assert!(actual.err.contains("The table only has 3 rows (0 to 2)"),)
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual.err.contains("There isn't a row indexed at 3"),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual.err.contains("The table only has 3 rows (0 to 2)"),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,13 +83,7 @@ fn errors_if_no_columns_present() {
|
|||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("no column names available"));
|
||||||
actual.err.contains("no column names available"),
|
assert!(actual.err.contains("can't rename"));
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
actual.err.contains("can't rename"),
|
|
||||||
format!("actual: {:?}", actual.err)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ pub fn get_color_config() -> HashMap<String, Style> {
|
|||||||
hm.insert("index_color".to_string(), Color::Green.bold());
|
hm.insert("index_color".to_string(), Color::Green.bold());
|
||||||
hm.insert(
|
hm.insert(
|
||||||
"leading_trailing_space_bg".to_string(),
|
"leading_trailing_space_bg".to_string(),
|
||||||
Style::default().on(Color::RGB(128, 128, 128)),
|
Style::default().on(Color::Rgb(128, 128, 128)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// populate hashmap from config values
|
// populate hashmap from config values
|
||||||
|
@ -241,7 +241,7 @@ impl ThemeColor {
|
|||||||
let r = ThemeColor::xtoi(&mut bytes)?;
|
let r = ThemeColor::xtoi(&mut bytes)?;
|
||||||
let g = ThemeColor::xtoi(&mut bytes)?;
|
let g = ThemeColor::xtoi(&mut bytes)?;
|
||||||
let b = ThemeColor::xtoi(&mut bytes)?;
|
let b = ThemeColor::xtoi(&mut bytes)?;
|
||||||
Ok(ThemeColor(Color::RGB(r, g, b)))
|
Ok(ThemeColor(Color::Rgb(r, g, b)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xtoi<E>(b: &mut Bytes) -> Result<u8, E>
|
fn xtoi<E>(b: &mut Bytes) -> Result<u8, E>
|
||||||
@ -329,7 +329,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
styled[0],
|
styled[0],
|
||||||
Spanned {
|
Spanned {
|
||||||
item: Color::RGB(163, 89, 204).bold(),
|
item: Color::Rgb(163, 89, 204).bold(),
|
||||||
span: Span::new(4, 9),
|
span: Span::new(4, 9),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -105,7 +105,7 @@ where
|
|||||||
return visitor.visit_str(s);
|
return visitor.visit_str(s);
|
||||||
} else if ch <= b' ' {
|
} else if ch <= b' ' {
|
||||||
if ch == 0 {
|
if ch == 0 {
|
||||||
return Err(self.rdr.error(ErrorCode::EOFWhileParsingObject));
|
return Err(self.rdr.error(ErrorCode::EofWhileParsingObject));
|
||||||
} else if space.is_none() {
|
} else if space.is_none() {
|
||||||
space = Some(self.str_buf.len());
|
space = Some(self.str_buf.len());
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ where
|
|||||||
self.rdr.parse_whitespace()?;
|
self.rdr.parse_whitespace()?;
|
||||||
|
|
||||||
if self.rdr.eof()? {
|
if self.rdr.eof()? {
|
||||||
return Err(self.rdr.error(ErrorCode::EOFWhileParsingValue));
|
return Err(self.rdr.error(ErrorCode::EofWhileParsingValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.state {
|
match self.state {
|
||||||
@ -162,7 +162,7 @@ where
|
|||||||
match self.rdr.next_char()? {
|
match self.rdr.next_char()? {
|
||||||
Some(b']') => Ok(ret),
|
Some(b']') => Ok(ret),
|
||||||
Some(_) => Err(self.rdr.error(ErrorCode::TrailingCharacters)),
|
Some(_) => Err(self.rdr.error(ErrorCode::TrailingCharacters)),
|
||||||
None => Err(self.rdr.error(ErrorCode::EOFWhileParsingList)),
|
None => Err(self.rdr.error(ErrorCode::EofWhileParsingList)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b'{' => {
|
b'{' => {
|
||||||
@ -193,7 +193,7 @@ where
|
|||||||
if root {
|
if root {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
} else {
|
} else {
|
||||||
Err(self.rdr.error(ErrorCode::EOFWhileParsingObject))
|
Err(self.rdr.error(ErrorCode::EofWhileParsingObject))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ where
|
|||||||
// When parsing multiline string values, we must look for ' characters.
|
// When parsing multiline string values, we must look for ' characters.
|
||||||
loop {
|
loop {
|
||||||
if self.rdr.eof()? {
|
if self.rdr.eof()? {
|
||||||
return Err(self.rdr.error(ErrorCode::EOFWhileParsingString));
|
return Err(self.rdr.error(ErrorCode::EofWhileParsingString));
|
||||||
} // todo error("Bad multiline string");
|
} // todo error("Bad multiline string");
|
||||||
let ch = self.rdr.next_char_or_null()?;
|
let ch = self.rdr.next_char_or_null()?;
|
||||||
|
|
||||||
@ -413,7 +413,7 @@ where
|
|||||||
let ch = match self.rdr.next_char()? {
|
let ch = match self.rdr.next_char()? {
|
||||||
Some(ch) => ch,
|
Some(ch) => ch,
|
||||||
None => {
|
None => {
|
||||||
return Err(self.rdr.error(ErrorCode::EOFWhileParsingString));
|
return Err(self.rdr.error(ErrorCode::EofWhileParsingString));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ where
|
|||||||
let ch = match self.rdr.next_char()? {
|
let ch = match self.rdr.next_char()? {
|
||||||
Some(ch) => ch,
|
Some(ch) => ch,
|
||||||
None => {
|
None => {
|
||||||
return Err(self.rdr.error(ErrorCode::EOFWhileParsingString));
|
return Err(self.rdr.error(ErrorCode::EofWhileParsingString));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ where
|
|||||||
match self.rdr.next_char()? {
|
match self.rdr.next_char()? {
|
||||||
Some(b':') => Ok(()),
|
Some(b':') => Ok(()),
|
||||||
Some(_) => Err(self.rdr.error(ErrorCode::ExpectedColon)),
|
Some(_) => Err(self.rdr.error(ErrorCode::ExpectedColon)),
|
||||||
None => Err(self.rdr.error(ErrorCode::EOFWhileParsingObject)),
|
None => Err(self.rdr.error(ErrorCode::EofWhileParsingObject)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,7 +592,7 @@ where
|
|||||||
}
|
}
|
||||||
Some(_) => {}
|
Some(_) => {}
|
||||||
None => {
|
None => {
|
||||||
return Err(self.de.rdr.error(ErrorCode::EOFWhileParsingList));
|
return Err(self.de.rdr.error(ErrorCode::EofWhileParsingList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +652,7 @@ where
|
|||||||
if self.root {
|
if self.root {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else {
|
} else {
|
||||||
return Err(self.de.rdr.error(ErrorCode::EOFWhileParsingObject));
|
return Err(self.de.rdr.error(ErrorCode::EofWhileParsingObject));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -666,7 +666,7 @@ where
|
|||||||
};
|
};
|
||||||
Ok(Some(seed.deserialize(&mut *self.de)?))
|
Ok(Some(seed.deserialize(&mut *self.de)?))
|
||||||
}
|
}
|
||||||
None => Err(self.de.rdr.error(ErrorCode::EOFWhileParsingValue)),
|
None => Err(self.de.rdr.error(ErrorCode::EofWhileParsingValue)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,7 +676,7 @@ where
|
|||||||
{
|
{
|
||||||
self.de.parse_object_colon()?;
|
self.de.parse_object_colon()?;
|
||||||
|
|
||||||
Ok(seed.deserialize(&mut *self.de)?)
|
seed.deserialize(&mut *self.de)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,16 +19,16 @@ pub enum ErrorCode {
|
|||||||
Custom(String),
|
Custom(String),
|
||||||
|
|
||||||
/// EOF while parsing a list.
|
/// EOF while parsing a list.
|
||||||
EOFWhileParsingList,
|
EofWhileParsingList,
|
||||||
|
|
||||||
/// EOF while parsing an object.
|
/// EOF while parsing an object.
|
||||||
EOFWhileParsingObject,
|
EofWhileParsingObject,
|
||||||
|
|
||||||
/// EOF while parsing a string.
|
/// EOF while parsing a string.
|
||||||
EOFWhileParsingString,
|
EofWhileParsingString,
|
||||||
|
|
||||||
/// EOF while parsing a JSON value.
|
/// EOF while parsing a JSON value.
|
||||||
EOFWhileParsingValue,
|
EofWhileParsingValue,
|
||||||
|
|
||||||
/// Expected this character to be a `':'`.
|
/// Expected this character to be a `':'`.
|
||||||
ExpectedColon,
|
ExpectedColon,
|
||||||
@ -76,10 +76,10 @@ impl fmt::Debug for ErrorCode {
|
|||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
ErrorCode::Custom(ref msg) => write!(f, "{}", msg),
|
ErrorCode::Custom(ref msg) => write!(f, "{}", msg),
|
||||||
ErrorCode::EOFWhileParsingList => "EOF while parsing a list".fmt(f),
|
ErrorCode::EofWhileParsingList => "EOF while parsing a list".fmt(f),
|
||||||
ErrorCode::EOFWhileParsingObject => "EOF while parsing an object".fmt(f),
|
ErrorCode::EofWhileParsingObject => "EOF while parsing an object".fmt(f),
|
||||||
ErrorCode::EOFWhileParsingString => "EOF while parsing a string".fmt(f),
|
ErrorCode::EofWhileParsingString => "EOF while parsing a string".fmt(f),
|
||||||
ErrorCode::EOFWhileParsingValue => "EOF while parsing a value".fmt(f),
|
ErrorCode::EofWhileParsingValue => "EOF while parsing a value".fmt(f),
|
||||||
ErrorCode::ExpectedColon => "expected `:`".fmt(f),
|
ErrorCode::ExpectedColon => "expected `:`".fmt(f),
|
||||||
ErrorCode::ExpectedListCommaOrEnd => "expected `,` or `]`".fmt(f),
|
ErrorCode::ExpectedListCommaOrEnd => "expected `,` or `]`".fmt(f),
|
||||||
ErrorCode::ExpectedObjectCommaOrEnd => "expected `,` or `}`".fmt(f),
|
ErrorCode::ExpectedObjectCommaOrEnd => "expected `,` or `}`".fmt(f),
|
||||||
|
@ -1092,7 +1092,7 @@ impl<'de, 'a> de::MapAccess<'de> for MapDeserializer {
|
|||||||
V: de::DeserializeSeed<'de>,
|
V: de::DeserializeSeed<'de>,
|
||||||
{
|
{
|
||||||
let value = self.value.take().expect("value is missing");
|
let value = self.value.take().expect("value is missing");
|
||||||
Ok(seed.deserialize(value)?)
|
seed.deserialize(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> Option<usize> {
|
fn size_hint(&self) -> Option<usize> {
|
||||||
@ -1150,18 +1150,18 @@ mod test {
|
|||||||
|
|
||||||
let v: Value = from_str("{\"a\":1.1}").unwrap();
|
let v: Value = from_str("{\"a\":1.1}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert_eq!(vo["a"].as_f64().unwrap(), 1.1);
|
assert!(vo["a"].as_f64().unwrap() - 1.1 < std::f64::EPSILON);
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":-1.1}").unwrap();
|
let v: Value = from_str("{\"a\":-1.1}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert_eq!(vo["a"].as_f64().unwrap(), -1.1);
|
assert!(vo["a"].as_f64().unwrap() + 1.1 > -(std::f64::EPSILON));
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":1e6}").unwrap();
|
let v: Value = from_str("{\"a\":1e6}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert_eq!(vo["a"].as_f64().unwrap(), 1e6);
|
assert!(vo["a"].as_f64().unwrap() - 1e6 < std::f64::EPSILON);
|
||||||
|
|
||||||
let v: Value = from_str("{\"a\":-1e6}").unwrap();
|
let v: Value = from_str("{\"a\":-1e6}").unwrap();
|
||||||
let vo = v.as_object().unwrap();
|
let vo = v.as_object().unwrap();
|
||||||
assert_eq!(vo["a"].as_f64().unwrap(), -1e6);
|
assert!(vo["a"].as_f64().unwrap() + 1e6 > -(std::f64::EPSILON));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ fn fix_pass1(json: String) -> String {
|
|||||||
fn test_hjson() {
|
fn test_hjson() {
|
||||||
let mut done: Vec<String> = Vec::new();
|
let mut done: Vec<String> = Vec::new();
|
||||||
|
|
||||||
println!("");
|
println!();
|
||||||
run_test!(charset, done, std_fix);
|
run_test!(charset, done, std_fix);
|
||||||
run_test!(comments, done, std_fix);
|
run_test!(comments, done, std_fix);
|
||||||
run_test!(empty, done, std_fix);
|
run_test!(empty, done, std_fix);
|
||||||
@ -197,18 +197,17 @@ fn test_hjson() {
|
|||||||
|
|
||||||
let all = paths
|
let all = paths
|
||||||
.map(|item| String::from(item.unwrap().path().file_stem().unwrap().to_str().unwrap()))
|
.map(|item| String::from(item.unwrap().path().file_stem().unwrap().to_str().unwrap()))
|
||||||
.filter(|x| x.contains("_test"))
|
.filter(|x| x.contains("_test"));
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
let missing = all
|
let missing = all
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|x| done.iter().find(|y| &x == y) == None)
|
.filter(|x| done.iter().find(|y| &x == y) == None)
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
if missing.len() > 0 {
|
if !missing.is_empty() {
|
||||||
for item in missing {
|
for item in missing {
|
||||||
println!("missing: {}", item);
|
println!("missing: {}", item);
|
||||||
}
|
}
|
||||||
assert!(false);
|
panic!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,12 +360,12 @@ pub fn parse_block(tokens: Vec<Token>) -> (LiteBlock, Option<ParseError>) {
|
|||||||
// - semicolon
|
// - semicolon
|
||||||
while let Some(token) = tokens.next() {
|
while let Some(token) = tokens.next() {
|
||||||
match &token.contents {
|
match &token.contents {
|
||||||
TokenContents::EOL => {
|
TokenContents::Eol => {
|
||||||
// If we encounter two newline characters in a row, use a special eoleol event,
|
// If we encounter two newline characters in a row, use a special eoleol event,
|
||||||
// which allows the parser to discard comments that shouldn't be treated as
|
// which allows the parser to discard comments that shouldn't be treated as
|
||||||
// documentation for the following item.
|
// documentation for the following item.
|
||||||
if let Some(Token {
|
if let Some(Token {
|
||||||
contents: TokenContents::EOL,
|
contents: TokenContents::Eol,
|
||||||
..
|
..
|
||||||
}) = tokens.peek()
|
}) = tokens.peek()
|
||||||
{
|
{
|
||||||
@ -480,7 +480,7 @@ pub fn lex(input: &str, span_offset: usize) -> (Vec<Token>, Option<ParseError>)
|
|||||||
let idx = *idx;
|
let idx = *idx;
|
||||||
let _ = char_indices.next();
|
let _ = char_indices.next();
|
||||||
output.push(Token::new(
|
output.push(Token::new(
|
||||||
TokenContents::EOL,
|
TokenContents::Eol,
|
||||||
Span::new(span_offset + idx, span_offset + idx + 1),
|
Span::new(span_offset + idx, span_offset + idx + 1),
|
||||||
));
|
));
|
||||||
} else if *c == '#' {
|
} else if *c == '#' {
|
||||||
|
@ -19,7 +19,7 @@ pub enum TokenContents {
|
|||||||
Comment(LiteComment),
|
Comment(LiteComment),
|
||||||
Pipe,
|
Pipe,
|
||||||
Semicolon,
|
Semicolon,
|
||||||
EOL,
|
Eol,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for TokenContents {
|
impl fmt::Display for TokenContents {
|
||||||
@ -29,7 +29,7 @@ impl fmt::Display for TokenContents {
|
|||||||
TokenContents::Comment(comm) => write!(f, "{}", comm),
|
TokenContents::Comment(comm) => write!(f, "{}", comm),
|
||||||
TokenContents::Pipe => write!(f, "|"),
|
TokenContents::Pipe => write!(f, "|"),
|
||||||
TokenContents::Semicolon => write!(f, ";"),
|
TokenContents::Semicolon => write!(f, ";"),
|
||||||
TokenContents::EOL => write!(f, "\\n"),
|
TokenContents::Eol => write!(f, "\\n"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,10 +71,7 @@ impl<'a, T: Plugin> PluginTest<'a, T> {
|
|||||||
for flag in flags {
|
for flag in flags {
|
||||||
assert!(
|
assert!(
|
||||||
flags_configured.iter().any(|f| *f == flag),
|
flags_configured.iter().any(|f| *f == flag),
|
||||||
format!(
|
"The flag you passed is not configured in the plugin.",
|
||||||
"The flag you passed ({}) is not configured in the plugin.",
|
|
||||||
flag
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +140,7 @@ pub fn expect_return_value_at(
|
|||||||
for (idx, item) in return_values.iter().enumerate() {
|
for (idx, item) in return_values.iter().enumerate() {
|
||||||
let item = match item {
|
let item = match item {
|
||||||
Ok(return_value) => return_value,
|
Ok(return_value) => return_value,
|
||||||
Err(reason) => panic!(format!("{}", reason)),
|
Err(_) => panic!("Unexpected value"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if idx == at {
|
if idx == at {
|
||||||
@ -155,9 +152,5 @@ pub fn expect_return_value_at(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!(format!(
|
panic!("Couldn't get return value from stream.")
|
||||||
"Couldn't get return value from stream at {}. (There are {} items)",
|
|
||||||
at,
|
|
||||||
return_values.len() - 1
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
@ -31,37 +31,39 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
|
fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
|
||||||
let mut table_headers = vec![];
|
let table_headers = vec![
|
||||||
table_headers.push("category");
|
"category",
|
||||||
table_headers.push("description");
|
"description",
|
||||||
table_headers.push("emoji");
|
"emoji",
|
||||||
table_headers.push("ios_version");
|
"ios_version",
|
||||||
table_headers.push("unicode_version");
|
"unicode_version",
|
||||||
table_headers.push("aliases");
|
"aliases",
|
||||||
table_headers.push("tags");
|
"tags",
|
||||||
table_headers.push("category2");
|
"category2",
|
||||||
table_headers.push("description2");
|
"description2",
|
||||||
table_headers.push("emoji2");
|
"emoji2",
|
||||||
table_headers.push("ios_version2");
|
"ios_version2",
|
||||||
table_headers.push("unicode_version2");
|
"unicode_version2",
|
||||||
table_headers.push("aliases2");
|
"aliases2",
|
||||||
table_headers.push("tags2");
|
"tags2",
|
||||||
|
];
|
||||||
|
|
||||||
let mut row_data = vec![];
|
let row_data = vec![
|
||||||
row_data.push("Smileys & Emotion");
|
"Smileys & Emotion",
|
||||||
row_data.push("grinning face");
|
"grinning face",
|
||||||
row_data.push("😀");
|
"😀",
|
||||||
row_data.push("6");
|
"6",
|
||||||
row_data.push("6.1");
|
"6.1",
|
||||||
row_data.push("grinning");
|
"grinning",
|
||||||
row_data.push("smile");
|
"smile",
|
||||||
row_data.push("Smileys & Emotion");
|
"Smileys & Emotion",
|
||||||
row_data.push("grinning face");
|
"grinning face",
|
||||||
row_data.push("😀");
|
"😀",
|
||||||
row_data.push("6");
|
"6",
|
||||||
row_data.push("6.1");
|
"6.1",
|
||||||
row_data.push("grinning");
|
"grinning",
|
||||||
row_data.push("smile");
|
"smile",
|
||||||
|
];
|
||||||
|
|
||||||
(table_headers, row_data)
|
(table_headers, row_data)
|
||||||
}
|
}
|
||||||
|
@ -196,8 +196,8 @@ pub fn delete_file_at(full_path: impl AsRef<Path>) {
|
|||||||
pub fn create_file_at(full_path: impl AsRef<Path>) -> Result<(), std::io::Error> {
|
pub fn create_file_at(full_path: impl AsRef<Path>) -> Result<(), std::io::Error> {
|
||||||
let full_path = full_path.as_ref();
|
let full_path = full_path.as_ref();
|
||||||
|
|
||||||
if let Some(parent) = full_path.parent() {
|
if full_path.parent().is_some() {
|
||||||
panic!(format!("{:?} exists", parent.display()));
|
panic!("path exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fs::write(full_path, b"fake data")
|
std::fs::write(full_path, b"fake data")
|
||||||
|
@ -63,7 +63,7 @@ impl RenderContext {
|
|||||||
Some(c) => {
|
Some(c) => {
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
nu_ansi_term::Color::RGB(c.0, c.1, c.2)
|
nu_ansi_term::Color::Rgb(c.0, c.1, c.2)
|
||||||
.paint((0..prev_count).map(|_| "█").collect::<String>())
|
.paint((0..prev_count).map(|_| "█").collect::<String>())
|
||||||
);
|
);
|
||||||
prev_color = Some(*pixel);
|
prev_color = Some(*pixel);
|
||||||
@ -80,7 +80,7 @@ impl RenderContext {
|
|||||||
if let Some(color) = prev_color {
|
if let Some(color) = prev_color {
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
nu_ansi_term::Color::RGB(color.0, color.1, color.2)
|
nu_ansi_term::Color::Rgb(color.0, color.1, color.2)
|
||||||
.paint((0..prev_count).map(|_| "█").collect::<String>())
|
.paint((0..prev_count).map(|_| "█").collect::<String>())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -108,8 +108,8 @@ impl RenderContext {
|
|||||||
(Some(c), Some(d)) => {
|
(Some(c), Some(d)) => {
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
nu_ansi_term::Color::RGB(c.0, c.1, c.2)
|
nu_ansi_term::Color::Rgb(c.0, c.1, c.2)
|
||||||
.on(nu_ansi_term::Color::RGB(d.0, d.1, d.2,))
|
.on(nu_ansi_term::Color::Rgb(d.0, d.1, d.2,))
|
||||||
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
||||||
);
|
);
|
||||||
prev_fg = Some(top_pixel);
|
prev_fg = Some(top_pixel);
|
||||||
@ -131,8 +131,8 @@ impl RenderContext {
|
|||||||
if let (Some(c), Some(d)) = (prev_fg, prev_bg) {
|
if let (Some(c), Some(d)) = (prev_fg, prev_bg) {
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
nu_ansi_term::Color::RGB(c.0, c.1, c.2)
|
nu_ansi_term::Color::Rgb(c.0, c.1, c.2)
|
||||||
.on(nu_ansi_term::Color::RGB(d.0, d.1, d.2,))
|
.on(nu_ansi_term::Color::Rgb(d.0, d.1, d.2,))
|
||||||
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ use nu_source::{SpannedItem, Tag};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FromBSON {
|
pub struct FromBson {
|
||||||
pub state: Vec<u8>,
|
pub state: Vec<u8>,
|
||||||
pub name_tag: Tag,
|
pub name_tag: Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromBSON {
|
impl FromBson {
|
||||||
pub fn new() -> FromBSON {
|
pub fn new() -> FromBson {
|
||||||
FromBSON {
|
FromBson {
|
||||||
state: vec![],
|
state: vec![],
|
||||||
name_tag: Tag::unknown(),
|
name_tag: Tag::unknown(),
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
mod from_bson;
|
mod from_bson;
|
||||||
mod nu;
|
mod nu;
|
||||||
|
|
||||||
pub use from_bson::FromBSON;
|
pub use from_bson::FromBson;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_plugin::serve_plugin;
|
use nu_plugin::serve_plugin;
|
||||||
use nu_plugin_from_bson::FromBSON;
|
use nu_plugin_from_bson::FromBson;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
serve_plugin(&mut FromBSON::new())
|
serve_plugin(&mut FromBson::new())
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use crate::FromBSON;
|
use crate::FromBson;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_plugin::Plugin;
|
use nu_plugin::Plugin;
|
||||||
use nu_protocol::{CallInfo, Primitive, ReturnValue, Signature, UntaggedValue, Value};
|
use nu_protocol::{CallInfo, Primitive, ReturnValue, Signature, UntaggedValue, Value};
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
|
|
||||||
impl Plugin for FromBSON {
|
impl Plugin for FromBson {
|
||||||
fn config(&mut self) -> Result<Signature, ShellError> {
|
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||||
Ok(Signature::build("from bson")
|
Ok(Signature::build("from bson")
|
||||||
.desc("Convert from .bson binary into table")
|
.desc("Convert from .bson binary into table")
|
||||||
|
@ -14,24 +14,21 @@ mod tests {
|
|||||||
pub fn expect_action(&self, action: Action) {
|
pub fn expect_action(&self, action: Action) {
|
||||||
match &self.action {
|
match &self.action {
|
||||||
Some(set) if set == &action => {}
|
Some(set) if set == &action => {}
|
||||||
Some(other) => panic!(format!("\nExpected {:#?}\n\ngot {:#?}", action, other)),
|
Some(_) => panic!("\nUnexpected action"),
|
||||||
None => panic!(format!("\nAction {:#?} not found.", action)),
|
None => panic!("\nAction not found."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_field(&self, field: Value) {
|
pub fn expect_field(&self, field: Value) {
|
||||||
let field = match field.as_column_path() {
|
let field = match field.as_column_path() {
|
||||||
Ok(column_path) => column_path,
|
Ok(column_path) => column_path,
|
||||||
Err(reason) => panic!(format!(
|
Err(_) => panic!("\nExpected a ColumnPath",),
|
||||||
"\nExpected {:#?} to be a ColumnPath, \n\ngot {:#?}",
|
|
||||||
field, reason
|
|
||||||
)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match &self.field {
|
match &self.field {
|
||||||
Some(column_path) if column_path == &field => {}
|
Some(column_path) if column_path == &field => {}
|
||||||
Some(other) => panic!(format!("\nExpected {:#?} \n\ngot {:#?}", field, other)),
|
Some(_) => panic!("\nUnexpected field."),
|
||||||
None => panic!(format!("\nField {:#?} not found.", field)),
|
None => panic!("\nField not found."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
mod nu;
|
mod nu;
|
||||||
mod to_bson;
|
mod to_bson;
|
||||||
|
|
||||||
pub use to_bson::ToBSON;
|
pub use to_bson::ToBson;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_plugin::serve_plugin;
|
use nu_plugin::serve_plugin;
|
||||||
use nu_plugin_to_bson::ToBSON;
|
use nu_plugin_to_bson::ToBson;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
serve_plugin(&mut ToBSON::new())
|
serve_plugin(&mut ToBson::new())
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use crate::ToBSON;
|
use crate::ToBson;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_plugin::Plugin;
|
use nu_plugin::Plugin;
|
||||||
use nu_protocol::{ReturnValue, Signature, Value};
|
use nu_protocol::{ReturnValue, Signature, Value};
|
||||||
use nu_source::Tag;
|
use nu_source::Tag;
|
||||||
|
|
||||||
impl Plugin for ToBSON {
|
impl Plugin for ToBson {
|
||||||
fn config(&mut self) -> Result<Signature, ShellError> {
|
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||||
Ok(Signature::build("to bson")
|
Ok(Signature::build("to bson")
|
||||||
.desc("Convert table into .bson binary")
|
.desc("Convert table into .bson binary")
|
||||||
|
@ -9,13 +9,13 @@ use num_traits::ToPrimitive;
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ToBSON {
|
pub struct ToBson {
|
||||||
pub state: Vec<Value>,
|
pub state: Vec<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToBSON {
|
impl ToBson {
|
||||||
pub fn new() -> ToBSON {
|
pub fn new() -> ToBson {
|
||||||
ToBSON { state: vec![] }
|
ToBson { state: vec![] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_plugin::serve_plugin;
|
use nu_plugin::serve_plugin;
|
||||||
use nu_plugin_from_bson::FromBSON;
|
use nu_plugin_from_bson::FromBson;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
serve_plugin(&mut FromBSON::new());
|
serve_plugin(&mut FromBson::new());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use nu_plugin::serve_plugin;
|
use nu_plugin::serve_plugin;
|
||||||
use nu_plugin_to_bson::ToBSON;
|
use nu_plugin_to_bson::ToBson;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
serve_plugin(&mut ToBSON::new())
|
serve_plugin(&mut ToBson::new())
|
||||||
}
|
}
|
||||||
|
@ -259,10 +259,7 @@ mod tilde_expansion {
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(
|
assert!(!actual.out.contains('~'));
|
||||||
!actual.out.contains('~'),
|
|
||||||
format!("'{}' should not contain ~", actual.out)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -716,49 +716,25 @@ mod parse {
|
|||||||
fn errors_if_flag_passed_is_not_exact() {
|
fn errors_if_flag_passed_is_not_exact() {
|
||||||
let actual = nu!(cwd: ".", "debug -ra");
|
let actual = nu!(cwd: ".", "debug -ra");
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("unexpected flag"),);
|
||||||
actual.err.contains("unexpected flag"),
|
|
||||||
format!(
|
|
||||||
"error message '{}' should contain 'unexpected flag'",
|
|
||||||
actual.err
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
let actual = nu!(cwd: ".", "debug --rawx");
|
let actual = nu!(cwd: ".", "debug --rawx");
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("unexpected flag"),);
|
||||||
actual.err.contains("unexpected flag"),
|
|
||||||
format!(
|
|
||||||
"error message '{}' should contain 'unexpected flag'",
|
|
||||||
actual.err
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_if_flag_is_not_supported() {
|
fn errors_if_flag_is_not_supported() {
|
||||||
let actual = nu!(cwd: ".", "debug --ferris");
|
let actual = nu!(cwd: ".", "debug --ferris");
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("unexpected flag"),);
|
||||||
actual.err.contains("unexpected flag"),
|
|
||||||
format!(
|
|
||||||
"error message '{}' should contain 'unexpected flag'",
|
|
||||||
actual.err
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_if_passed_an_unexpected_argument() {
|
fn errors_if_passed_an_unexpected_argument() {
|
||||||
let actual = nu!(cwd: ".", "debug ferris");
|
let actual = nu!(cwd: ".", "debug ferris");
|
||||||
|
|
||||||
assert!(
|
assert!(actual.err.contains("unexpected argument"),);
|
||||||
actual.err.contains("unexpected argument"),
|
|
||||||
format!(
|
|
||||||
"error message '{}' should contain 'unexpected argument'",
|
|
||||||
actual.err
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,10 +751,7 @@ mod tilde_expansion {
|
|||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(
|
assert!(!actual.out.contains('~'),);
|
||||||
!actual.out.contains('~'),
|
|
||||||
format!("'{}' should not contain ~", actual.out)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user