nushell/crates
Adam Schmalhofer 04fed82e5e
Feature url build_query accepts records with lists of strings (#14073)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description

<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->

Swagger supports lists (a.k.a arrays) in query parameters:

https://swagger.io/docs/specification/v3_0/serialization/
It supports three different styles:
- explode=true
- spaceDelimited
- pipeDelimited
With explode=true being the default and hence most common. It is the
hardest to use inside of nushell, as the others are just a `string join`
away. This commit adds lists with the explode=true format.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

Before:

: {a[]: [one two three], b: four} | url build-query
Error: nu:🐚:unsupported_input
× Unsupported input
╭─[entry #33:1:1]
1 │ {a[]: [one two three], b: four} | url build-query
· ───────────────┬─────────────── ───────┬───────
· │ ╰── Expected a record with string values
· ╰── value originates from here
       ╰────

After:

: {a[]: [one two three], b: four} | url build-query
    a%5B%5D=one&a%5B%5D=two&a%5B%5D=three&b=four


Despite reading CONTRIBUTING.md I didn't get approval before making the
change. My judgment is that this doesn't qualify as being "change
something significantly".

# Tests + Formatting

I added the Example instance for the automatic tests. I couldn't figure
out how to add an Example for the error case, so I did that with manual
testing. E.g.:

: {a[]: [one two [three]], b: four} | url build-query

Error: nu:🐚:unsupported_input


× Unsupported input

╭─[entry #3:1:1]

1 │ {a[]: [one two [three]], b: four} | url build-query

· ────────────────┬──────────────── ───────┬───────

· │ ╰── Expected a record with list of string values

· ╰── value originates from here

       ╰────

: {a[]: [one two 3hr], b: four} | url build-query

Error: nu:🐚:unsupported_input


× Unsupported input

╭─[entry #4:1:1]

1 │ {a[]: [one two 3hr], b: four} | url build-query

· ──────────────┬────────────── ───────┬───────

· │ ╰── Expected a record with list of string values

· ╰── value originates from here

       ╰──── 
<!--
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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

I ran the four cargo commands on my local machine. I had to run the
tests with:

LANG=C and -j 1 and even then I got one failure:

thread 'commands::umkdir::mkdir_umask_permission' panicked at
crates/nu-command/tests/commands/umkdir.rs:148:9:
assertion `left == right` failed: Most *nix systems have 0o00022 as the
umask. So directory permission should be 0o40755 = 0o
40777 & (!0o00022)
left: 16893
    right: 16877

but this isn't related to this change (I seem to not be running most
*nix system; and don't have a lot of RAM for the number of cores). The
other three cargo commands didn't have errors or warnings.

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

I will add the new example to [the
documentation](https://github.com/nushell/nushell.github.io).

# Open questions / possible future work

Things I noticed, and would like to mention and am open to adding, but
don't think I am deep enough in nushell to do them pro-actively.

## Add an argument for the other query parameter list styles

I don't know how frequent they are and I currently don't need them, so
following KISS I didn't add them.

## long input_span marked

In e.g.:

: {a[]: [one two 3hr], b: four} | url build-query

Error: nu:🐚:unsupported_input


× Unsupported input

╭─[entry #4:1:1]

1 │ {a[]: [one two 3hr], b: four} | url build-query

· ──────────────┬────────────── ───────┬───────

· │ ╰── Expected a record with list of string values

· ╰── value originates from here

       ╰──── 

the entire record is marked as input_span instead of just the "3hr" that
is causing the problem. Changing that would be trivial, but I'm not deep
enough into nushell to understand all the consequences of changing that.


## Error message says string values despite accepting numbers etc.

The error message said it only accepted strings despite accepting
numbers etc. (anything it can coerce into string). I couldn't find a
good wording myself and that was how it was before. I simply added a
"list of strings".
2024-10-22 10:38:25 -05:00
..
nu_plugin_custom_values Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_example Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_formats Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_gstat Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_inc Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_nu_example Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_polars run ensure_flag_arg_type for short flag values (#14074) 2024-10-20 23:12:57 +02:00
nu_plugin_python Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_query Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu_plugin_stress_internals Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-cli try and fix osc633 escaping yet again (#14140) 2024-10-21 21:57:58 +02:00
nu-cmd-base Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-cmd-extra Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-cmd-lang add rendered and json error messages in try/catch (#14082) 2024-10-20 23:14:11 +02:00
nu-cmd-plugin Make plugin list read state from plugin registry file as well (#14085) 2024-10-20 23:12:57 +02:00
nu-color-config Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-command Feature url build_query accepts records with lists of strings (#14073) 2024-10-22 10:38:25 -05:00
nu-derive-value Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-engine add is_const to help commands and scope commands (#14125) 2024-10-21 12:54:18 +02:00
nu-explore Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-glob Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-json Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-lsp Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-parser Fix panic if tokens are placed after a redirection (#14035) 2024-10-22 10:37:03 -05:00
nu-path Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-plugin Update to rust 1.80.1 (#14106) 2024-10-20 23:14:11 +02:00
nu-plugin-core Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-plugin-engine Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-plugin-protocol Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-plugin-test-support Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-pretty-hex Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-protocol Fix range contains (#14011) 2024-10-22 10:34:41 -05:00
nu-std add like and not-like operators as synonyms for the regex operators =~ and !~ (#14072) 2024-10-20 23:12:57 +02:00
nu-system add start_time to ps -l on macos (#14127) 2024-10-21 11:55:30 -05:00
nu-table Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-term-grid Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-test-support Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nu-utils Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
nuon Bump to 0.99.2 (#14136) 2024-10-20 23:12:41 +02:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.