Skip to content

add the example results to the documentation pages #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2023
Merged

add the example results to the documentation pages #807

merged 2 commits into from
Mar 5, 2023

Conversation

amtoine
Copy link
Member

@amtoine amtoine commented Mar 5, 2023

Related to

As introduced in nushell/nushell#8189 and nushell/nushell#8319, the $nu.scope.commands structure now holds the results of the command examples 👍

in order to generate accurate documentation pages, the make_docs.nu script needs to use $nu.scope.commands.example.result in addition to $nu.scope.commands.example.description and $nu.scope.commands.example.example

this PR uses $example.result in the command-doc command right after the > ($example.example) line, adding the result to the page.

Note
in order to print real structured data, i could not use $example.result only, e.g. it would print raw string data even with tables...
the easiest i found was to try to --expand the $example.result and catch the input as default, i.e. when the result is not --expandable 👍

example

on the merge command

>_ nu make_docs.nu
>_ git diff commands/docs/merge.md | str replace --all "```" "``"

gives

diff --git a/commands/docs/merge.md b/commands/docs/merge.md
index 0671dc8e63..68482f9a8a 100644
--- a/commands/docs/merge.md
+++ b/commands/docs/merge.md
@@ -32,14 +32,33 @@ repeating this process with row 1, and so on.
 Add an 'index' column to the input table
 ``shell
 > [a b c] | wrap name | merge ( [1 2 3] | wrap index )
+╭───┬──────╮
+│ # │ name │
+├───┼──────┤
+│ 1 │ a    │
+│ 2 │ b    │
+│ 3 │ c    │
+╰───┴──────╯
+
 ``
 
 Merge two records
 ``shell
 > {a: 1, b: 2} | merge {c: 3}
+╭───┬───╮
+│ a │ 1 │
+│ b │ 2 │
+│ c │ 3 │
+╰───┴───╯
 ``
 
 Merge two tables, overwriting overlapping columns
 ``shell
 > [{columnA: A0 columnB: B0}] | merge [{columnA: 'A0*'}]
+╭───┬─────────┬─────────╮
+│ # │ columnA │ columnB │
+├───┼─────────┼─────────┤
+│ 0 │ A0*     │ B0      │
+╰───┴─────────┴─────────╯
+
 ``

amtoine added 2 commits March 5, 2023 11:05
The easiest i found to do that is to `try` to `--expand` the
`example.result` and `catch` the input value if it's not possible.
@fdncred
Copy link
Contributor

fdncred commented Mar 5, 2023

nice. thanks!

@fdncred fdncred merged commit 5ed82fd into nushell:main Mar 5, 2023
@amtoine
Copy link
Member Author

amtoine commented Mar 5, 2023

nice. thanks!

🥳

@amtoine amtoine deleted the feature/add-the-example-results-to-the-documentation-pages branch March 5, 2023 16:38
ayax79 pushed a commit to ayax79/nushell.github.io that referenced this pull request Jun 26, 2024
1Password cli completions for all of the commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants