Skip to content

Commit

Permalink
Update docs for open and decode command, regenerate all docs (#4815)
Browse files Browse the repository at this point in the history
* Update docs for open and decode command, regenerate all docs

* Update open.rs

* Update open.md

Co-authored-by: JT <[email protected]>
  • Loading branch information
hustcer and sophiajt committed Mar 11, 2022
1 parent 7debb27 commit f3626f7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 19 deletions.
7 changes: 6 additions & 1 deletion crates/nu-command/src/filesystem/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Command for Open {
}

fn usage(&self) -> &str {
"Opens a file."
"Load a file into a cell, converting to table if possible (avoid by appending '--raw')."
}

fn signature(&self) -> nu_protocol::Signature {
Expand Down Expand Up @@ -172,6 +172,11 @@ impl Command for Open {
example: "echo 'myfile.txt' | open",
result: None,
},
Example {
description: "Open a file, and decode it by the specified encoding",
example: "open myfile.txt --raw | decode utf-8",
result: None,
},
]
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/nu-command/src/strings/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ impl Command for Decode {
.category(Category::Strings)
}

fn extra_usage(&self) -> &str {
r#"Multiple encodings are supported, here is an example of a few:
big5, euc-jp, euc-kr, gbk, iso-8859-1, utf-16, cp1252, latin5
For a more complete list of encodings please refer to the encoding_rs
documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"#
}

fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Decode the output of an external command",
Expand Down
13 changes: 9 additions & 4 deletions docs/commands/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ Sets a default row's column if missing.

## Signature

```> default (column name) (column value)```
```> default (default value) (column name)```

## Parameters

- `default value`: the value to use as a default
- `column name`: the name of the column
- `column value`: the value of the column to default

## Examples

Give a default 'target' to all file entries
Give a default 'target' column to all file entries
```shell
> ls -la | default target 'nothing'
> ls -la | default 'nothing' target
```

Default the `$nothing` value in a list
```shell
> [1, 2, $nothing, 4] | default 3
```
5 changes: 5 additions & 0 deletions docs/commands/do.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Run the block and ignore errors
```shell
> do -i { thisisnotarealcommand }
```
Run the block, with a positional parameter
```shell
> do {|x| 100 + $x } 50
```
13 changes: 6 additions & 7 deletions docs/commands/empty.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ Check for empty values.

## Signature

```> empty? ...rest --block```
```> empty? ...rest```

## Parameters

- `...rest`: the names of the columns to check emptiness
- `--block {block}`: an optional block to replace if empty

## Examples

Check if a value is empty
Check if a string is empty
```shell
> '' | empty?
```

more than one column
Check if a list is empty
```shell
> [[meal size]; [arepa small] [taco '']] | empty? meal size
> [] | empty?
```

use a block if setting the empty cell contents is wanted
Check if more than one column are empty
```shell
> [[2020/04/16 2020/07/10 2020/11/16]; ['' [27] [37]]] | empty? 2020/04/16 -b { |_| [33 37] }
> [[meal size]; [arepa small] [taco '']] | empty? meal size
```
11 changes: 11 additions & 0 deletions docs/commands/match.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: match
layout: command
version: 0.59.1
---

Deprecated command

## Signature

```> match ```
7 changes: 6 additions & 1 deletion docs/commands/open.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ layout: command
version: 0.59.1
---

Opens a file.
Load a file into a cell, converting to table if possible (avoid by appending '--raw').

## Signature

Expand All @@ -31,3 +31,8 @@ Open a file, using the input to get filename
```shell
> echo 'myfile.txt' | open
```

Open a file, and decode it by the specified encoding
```shell
> open myfile.txt --raw | decode utf-8
```
12 changes: 6 additions & 6 deletions docs/commands/reduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Replace selected characters in a string with 'X'
Find the longest string and its index
```shell
> [ one longest three bar ] | reduce -n { |it, acc|
if ($it.item | str length) > ($acc | str length) {
$it.item
} else {
$acc
}
}
if ($it.item | str length) > ($acc | str length) {
$it.item
} else {
$acc
}
}
```

0 comments on commit f3626f7

Please sign in to comment.