Skip to content

Std xml utils - #8437

Merged
fdncred merged 15 commits into
nushell:mainfrom
NotLebedev:std-xml-utils
Apr 5, 2023
Merged

fdncred merged 15 commits into
nushell:mainfrom
NotLebedev:std-xml-utils

Conversation

@NotLebedev

@NotLebedev NotLebedev commented Mar 13, 2023 •

Copy link
Copy Markdown
Contributor

Description

Add xaccess,xupdate and xinsert scripts to standard library. They allow accessing and manipulating data in new xml format #7947 with relative ease.

Access some data in nushell xml structure:
image

Update attributes of xml tags matching a path:
image

User-Facing Changes

New commands std xaccess, std xupdate and std xinsert

Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

Note
from nushell you can also use the toolkit as follows

use toolkit.nu  # or use an `env_change` hook to activate it automatically
toolkit check pr

After Submitting

If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.

@NotLebedev
NotLebedev marked this pull request as draft March 13, 2023 18:07
@codecov

codecov Bot commented Mar 13, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #8437 (7f77780) into main (0567407) will decrease coverage by 0.03%.
The diff coverage is n/a.

❗ Current head 7f77780 differs from pull request most recent head a51b668. Consider uploading reports for the commit a51b668 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8437      +/-   ##
==========================================
- Coverage   68.16%   68.13%   -0.03%     
==========================================
  Files         631      620      -11     
  Lines      101963    99723    -2240     
==========================================
- Hits        69502    67951    -1551     
+ Misses      32461    31772     -689     

see 105 files with indirect coverage changes

@fdncred fdncred added the A:std-library Defining and improving the standard library written in Nu label Mar 14, 2023
@amtoine

amtoine commented Mar 14, 2023

Copy link
Copy Markdown
Member

thanks for your contribution! 👋

the thing is i do not know XML at all, so i do not really know what to test and what behaviour to look after 😮

for instance

open Cargo.toml | to xml

does not even work 😆

in the meantime, i'll have a look at the source (but it looks already quite good and well documented, i like that 😏)

@amtoine amtoine left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really do not understand the XML format, that's even the first time i see it for real i think 😮

so i'll trust you and other XML-experts that the new xml module does what it's supposed to do 😌

only minor remarks and i'm wondering if aligning the right operands of the asserts would make them a bit easier to read?
i do not know, as you feel is the best.

Comment thread crates/nu-utils/standard_library/xml.nu Resolved
@NotLebedev
NotLebedev marked this pull request as ready for review April 2, 2023 11:34
@NotLebedev

Copy link
Copy Markdown
Contributor Author

Finished this. Fixed all recommendations, added one more useful command.

Regarding

the thing is i do not know XML at all, so i do not really know what to test and what behaviour to look after 😮

for instance

open Cargo.toml | to xml

does not even work 😆

this is the reason why this commands are required at all. Xml is a weird format among others because it is not a tabular or key-value format (which are easy to use in nushell) but a strange tag-attributes-content model, allowing repetitions of entries but placing many other arbitrary restrictions. This is why to xml and from xml commands accept and produce very specific format, consisting of record<tag attribute content>. The help for to xml and from xml describes it in more detail.

TL;DR xml does not map on json-like formats well, thus it can not be mapped one-to one with most nushell values in a sensible way.

@amtoine

amtoine commented Apr 4, 2023

Copy link
Copy Markdown
Member

@NotLebedev

thanks for the explaination, much appreciate it ❤️

i'm gonna review right now as it's ready 💪

@amtoine amtoine left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few little things, we're close 😋

Comment thread test.nu Resolved
@fdncred

fdncred commented Apr 5, 2023

Copy link
Copy Markdown
Contributor

@NotLebedev can we resolve the conflicts so we can land this please?

@fdncred

fdncred commented Apr 5, 2023

Copy link
Copy Markdown
Contributor

Thanks!

@fdncred
fdncred merged commit f723bc6 into nushell:main Apr 5, 2023
@NotLebedev
NotLebedev deleted the std-xml-utils branch April 5, 2023 19:01
@fdncred

fdncred commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

@NotLebedev any ideas why I'm getting errors with xaccess on linux?
image

@fdncred

fdncred commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

Sorry @NotLebedev - it was my fault. i had another match command defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:std-library Defining and improving the standard library written in Nu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants