mirror of
https://github.com/nushell/nushell.git
synced 2025-07-10 03:17:35 +02:00
# Description This PR makes the span of a pipeline accessible through `metadata`, meaning it's possible to get the span of a pipeline without collecting it. Examples: ```nushell ls | metadata # => ╭────────┬────────────────────╮ # => │ │ ╭───────┬────────╮ │ # => │ span │ │ start │ 170218 │ │ # => │ │ │ end │ 170220 │ │ # => │ │ ╰───────┴────────╯ │ # => │ source │ ls │ # => ╰────────┴────────────────────╯ ``` ```nushell ls | metadata access {|meta| error make {msg: "error", label: {text: "here", span: $meta.span}} } # => Error: × error # => ╭─[entry #7:1:1] # => 1 │ ls | metadata access {|meta| # => · ─┬ # => · ╰── here # => 2 │ error make {msg: "error", label: {text: "here", span: $meta.span}} # => ╰──── ``` Here's an example that wouldn't be possible before, since you would have to use `metadata $in` to get the span, collecting the (infinite) stream ```nushell generate {|x=0| {out: 0, next: 0} } | metadata access {|meta| # do whatever with stream error make {msg: "error", label: {text: "here", span: $meta.span}} } # => Error: × error # => ╭─[entry #16:1:1] # => 1 │ generate {|x=0| {out: 0, next: 0} } | metadata access {|meta| # => · ────┬─── # => · ╰── here # => 2 │ # do whatever with stream # => ╰──── ``` I haven't done the tests or anything yet since I'm not sure how we feel about having this as part of the normal metadata, rather than a new command like `metadata span` or something. We could also have a `metadata access` like functionality for that with an optional closure argument potentially. # User-Facing Changes * The span of a pipeline is now available through `metadata` and `metadata access` without collecting a stream. # Tests + Formatting TODO # After Submitting N/A
nu-protocol
The nu-protocol crate holds the definitions of structs/traits that are used throughout Nushell. This gives us one way to expose them to many other crates, as well as make these definitions available to each other, without causing mutually recursive dependencies.