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