Add long options for core and dataframes (#10619)

This commit is contained in:
Hofer-Julian 2023-10-06 18:55:29 +02:00 committed by GitHub
parent 0dbd014d8b
commit 7dbda76fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 26 additions and 25 deletions

View File

@ -52,12 +52,13 @@ impl Command for SampleDF {
vec![
Example {
description: "Sample rows from dataframe",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr sample -n 1",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr sample --n-rows 1",
result: None, // No expected value because sampling is random
},
Example {
description: "Shows sample row using fraction and replace",
example: "[[a b]; [1 2] [3 4] [5 6]] | dfr into-df | dfr sample -f 0.5 -e",
example:
"[[a b]; [1 2] [3 4] [5 6]] | dfr into-df | dfr sample --fraction 0.5 --replace",
result: None, // No expected value because sampling is random
},
]

View File

@ -45,7 +45,7 @@ impl Command for ToCSV {
},
Example {
description: "Saves dataframe to CSV file using other delimiter",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv -d '|'",
example: "[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv --delimiter '|'",
result: None,
},
]

View File

@ -61,7 +61,7 @@ impl Command for ToNu {
},
Example {
description: "Shows tail rows from dataframe",
example: "[[a b]; [1 2] [5 6] [3 4]] | dfr into-df | dfr into-nu -t -n 1",
example: "[[a b]; [1 2] [5 6] [3 4]] | dfr into-df | dfr into-nu --tail --rows 1",
result: Some(Value::list(vec![rec_3], Span::test_data())),
},
Example {

View File

@ -31,7 +31,7 @@ impl Command for GetDay {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns day from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-day"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetHour {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns hour from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-hour"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetMinute {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns minute from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-minute"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetMonth {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns month from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-month"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetNanosecond {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns nanosecond from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-nanosecond"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetOrdinal {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns ordinal from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-ordinal"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetSecond {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns second from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-second"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetWeek {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns week from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-week"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetWeekDay {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns weekday from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-weekday"#,
result: Some(

View File

@ -31,7 +31,7 @@ impl Command for GetYear {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns year from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-year"#,
result: Some(

View File

@ -61,7 +61,7 @@ impl Command for ArgSort {
},
Example {
description: "Returns indexes for a sorted series",
example: "[1 2 2 3 3] | dfr into-df | dfr arg-sort -r",
example: "[1 2 2 3 3] | dfr into-df | dfr arg-sort --reverse",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"arg_sort".to_string(),

View File

@ -41,7 +41,7 @@ impl Command for SetWithIndex {
description: "Set value in selected rows from series",
example: r#"let series = ([4 1 5 2 4 3] | dfr into-df);
let indices = ([0 2] | dfr into-df);
$series | dfr set-with-idx 6 -i $indices"#,
$series | dfr set-with-idx 6 --indices $indices"#,
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),

View File

@ -44,7 +44,7 @@ impl Command for Replace {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Replaces string",
example: "[abc abc abc] | dfr into-df | dfr replace -p ab -r AB",
example: "[abc abc abc] | dfr into-df | dfr replace --pattern ab --replace AB",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),

View File

@ -44,7 +44,7 @@ impl Command for ReplaceAll {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Replaces string",
example: "[abac abac abac] | dfr into-df | dfr replace-all -p a -r A",
example: "[abac abac abac] | dfr into-df | dfr replace-all --pattern a --replace A",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),

View File

@ -34,7 +34,7 @@ impl Command for StrSlice {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Creates slices from the strings",
example: "[abcded abc321 abc123] | dfr into-df | dfr str-slice 1 -l 2",
example: "[abcded abc321 abc123] | dfr into-df | dfr str-slice 1 --length 2",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),

View File

@ -33,7 +33,7 @@ impl Command for StrFTime {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Formats date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime --timezone 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr strftime "%Y/%m/%d""#,
result: Some(

View File

@ -275,22 +275,22 @@ impl Command for Do {
},
Example {
description: "Run the closure and ignore both shell and external program errors",
example: r#"do -i { thisisnotarealcommand }"#,
example: r#"do --ignore-errors { thisisnotarealcommand }"#,
result: None,
},
Example {
description: "Run the closure and ignore shell errors",
example: r#"do -s { thisisnotarealcommand }"#,
example: r#"do --ignore-shell-errors { thisisnotarealcommand }"#,
result: None,
},
Example {
description: "Run the closure and ignore external program errors",
example: r#"do -p { nu -c 'exit 1' }; echo "I'll still run""#,
example: r#"do --ignore-program-errors { nu --commands 'exit 1' }; echo "I'll still run""#,
result: None,
},
Example {
description: "Abort the pipeline if a program returns a non-zero exit code",
example: r#"do -c { nu -c 'exit 1' } | myscarycommand"#,
example: r#"do --capture-errors { nu --commands 'exit 1' } | myscarycommand"#,
result: None,
},
Example {

View File

@ -88,7 +88,7 @@ impl Command for LazyMake {
},
Example {
description: "Test the laziness of lazy records",
example: r#"lazy make -c ["hello"] -g { |key| print $"getting ($key)!"; $key | str upcase }"#,
example: r#"lazy make --columns ["hello"] --get-value { |key| print $"getting ($key)!"; $key | str upcase }"#,
result: None,
},
]