nushell / nushell.github.io

Nushell's main website, blog, book, and more
https://www.nushell.sh/book/
MIT License
169 stars 415 forks source link

`dataframes` chapter update a table with `commands` #1437

Closed maxim-uvarov closed 3 months ago

maxim-uvarov commented 4 months ago

I wrote a script to update the markdown table with commands. I'm not sure where to save it, as it might be useful for future updates. If anyone knows a proper place, please let me know. For now, I put it here.

let chapter = open dataframes.md
let book_table_str = $chapter 
    | lines 
    | skip until {|it| $it starts-with '| Command Name '} 
    | take until {|i| $i starts-with '## Future'}

let book_table = $book_table_str 
    | parse '| {command_name} | {applies_to} | {description} | {nushell_equivalent} |' 
    | skip 2 
    | str trim command_name nushell_equivalent 
    | rename name 
    | select name nushell_equivalent

let updated_table = help commands
    | where name =~ 'polars'
    | where name != 'polars'
    | update input_output {|i| $i.input_output.input | str join ', '}
    | select name input_output usage
    | join --left $book_table name
    | rename "Command Name" "Applies To" Description "Nushell Equivalent"
    | to md --pretty
    | str replace -ar "(( |-){47} \\|\n)" " \|\n"
    | $'($in)(char nl)'

$chapter | str replace ($book_table_str | str join (char nl)) $updated_table | save -f dataframes.md
ayax79 commented 4 months ago

The pull request looks good. I'll let @fdncred on the best place to save your script.

fdncred commented 3 months ago

@hustcer Thoughts on this PR? Is it ok to land it or will the docs script rewrite it? Where should the script be placed?

maxim-uvarov commented 3 months ago

The docs script never replaced the previous version of the table. Probably, it doesn't work with this kind of inline tables.

hustcer commented 3 months ago

Thanks,I will look into it later

maxim-uvarov commented 3 months ago

My script does two things:

  1. Updates the table with the current list of polars commands.
  2. Joins the updated table with the currently specified values in the Nushell Equivalent column of the current markdown table.

I put this script in the comment so that the next person who updates the chapter will have a chance to use it.

Please let me know if it is not okay. I will delete my comments from there.

hustcer commented 3 months ago

@maxim-uvarov I have just added the tools folder, maybe we can put the script there.

maxim-uvarov commented 3 months ago

@maxim-uvarov I have just added the tools folder, maybe we can put the script there.

@hustcer Thank you! I have moved the script there.

It should be okay to merge now. Gentlemen, please check.

hustcer commented 3 months ago

Thanks