docs/commands: add from.md, update subcommands (#1712)

This adds a top-level document for the new `from` command, with a list of links of all the subcommands.

All the from-* subcommands keep their filename, but the content is updated to use the new subcommand syntax.

Needs matching update for to*

Ref #1709
This commit is contained in:
Jörn Zaefferer
2020-05-04 23:01:31 +02:00
committed by GitHub
parent 3201c90647
commit 8ab2b92405
11 changed files with 111 additions and 59 deletions

View File

@@ -1,4 +1,4 @@
# from-csv
# from csv
Converts csv data into table. Use this when nushell cannot determine the input file extension.
@@ -24,10 +24,10 @@ dog, Alfred, 10
chameleon, Linda, 1
```
To get a table from `pets.txt` we need to use the `from-csv` command :
To get a table from `pets.txt` we need to use the `from csv` command :
```shell
> open pets.txt | from-csv
> open pets.txt | from csv
━━━┯━━━━━━━━━━━┯━━━━━━━━━┯━━━━━━
# │ animal │ name │ age
───┼───────────┼─────────┼──────
@@ -59,7 +59,7 @@ chameleon; Linda; 1
```
```shell
> open pets.txt | from-csv --separator ';'
> open pets.txt | from csv --separator ';'
━━━┯━━━━━━━━━━━┯━━━━━━━━━┯━━━━━━
# │ animal │ name │ age
───┼───────────┼─────────┼──────
@@ -69,20 +69,20 @@ chameleon; Linda; 1
━━━┷━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━
```
To use this command to open a csv with separators other than a comma, use the `--raw` switch of `open` to open the csv, otherwise the csv will enter `from-csv` as a table split on commas rather than raw text.
To use this command to open a csv with separators other than a comma, use the `--raw` switch of `open` to open the csv, otherwise the csv will enter `from csv` as a table split on commas rather than raw text.
```shell
> mv pets.txt pets.csv
> open pets.csv | from-csv --separator ';'
> open pets.csv | from csv --separator ';'
error: Expected a string from pipeline
- shell:1:16
1 | open pets.csv | from-csv --separator ';'
1 | open pets.csv | from csv --separator ';'
| ^^^^^^^^ requires string input
- shell:1:0
1 | open pets.csv | from-csv --separator ';'
1 | open pets.csv | from csv --separator ';'
| value originates from here
> open pets.csv --raw | from-csv --separator ';'
> open pets.csv --raw | from csv --separator ';'
━━━┯━━━━━━━━━━━┯━━━━━━━━━┯━━━━━━
# │ animal │ name │ age
───┼───────────┼─────────┼──────
@@ -99,18 +99,18 @@ Newlines '\n' are not acceptable separators.
Note that separators are currently provided as strings and need to be wrapped in quotes.
```shell
> open pets.csv --raw | from-csv --separator ;
> open pets.csv --raw | from csv --separator ;
- shell:1:43
1 | open pets.csv --raw | from-csv --separator ;
1 | open pets.csv --raw | from csv --separator ;
| ^
```
It is also considered an error to use a separator greater than one char :
```shell
> open pets.txt | from-csv --separator '123'
> open pets.txt | from csv --separator '123'
error: Expected a single separator char from --separator
- shell:1:37
1 | open pets.txt | from-csv --separator '123'
1 | open pets.txt | from csv --separator '123'
| ^^^^^ requires a single character string input
```