Add warning to url join when input key is not supported (#10506) (#10565)

<!--
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.
-->
Adds warning to `url join` when input key is not supported as suggested
by @amtoine in #10506.

It just adds a `println!` statement but it seems like that is all that
is done for other warnings, e.g.,
20aaaaf90c/crates/nu-glob/src/lib.rs (L434)

# 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` 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 std testing; testing run-tests --path
crates/nu-std"` 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
> ```
-->
All pass.
This commit is contained in:
Marshall Bruner 2023-10-02 13:47:02 +02:00 committed by GitHub
parent c4bbc3edad
commit 679879f79b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,7 +82,7 @@ impl Command for SubCommand {
fn run( fn run(
&self, &self,
_engine_state: &EngineState, engine_state: &EngineState,
_stack: &mut Stack, _stack: &mut Stack,
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
@ -98,7 +98,7 @@ impl Command for SubCommand {
let url_components = val let url_components = val
.into_iter() .into_iter()
.try_fold(UrlComponents::new(), |url, (k, v)| { .try_fold(UrlComponents::new(), |url, (k, v)| {
url.add_component(k, v, span) url.add_component(k, v, span, engine_state)
}); });
url_components?.to_url(span) url_components?.to_url(span)
@ -137,8 +137,14 @@ impl UrlComponents {
Default::default() Default::default()
} }
pub fn add_component(self, key: String, value: Value, _span: Span) -> Result<Self, ShellError> { pub fn add_component(
let span = value.span(); self,
key: String,
value: Value,
span: Span,
engine_state: &EngineState,
) -> Result<Self, ShellError> {
let value_span = value.span();
if key == "port" { if key == "port" {
return match value { return match value {
Value::String { val, .. } => { Value::String { val, .. } => {
@ -154,7 +160,7 @@ impl UrlComponents {
msg: String::from( msg: String::from(
"Port parameter should represent an unsigned integer", "Port parameter should represent an unsigned integer",
), ),
span, span: value_span,
}), }),
} }
} }
@ -205,7 +211,7 @@ impl UrlComponents {
Ok(Self { Ok(Self {
query: Some(qs), query: Some(qs),
params_span: Some(span), params_span: Some(value_span),
..self ..self
}) })
} }
@ -275,7 +281,19 @@ impl UrlComponents {
}), }),
..self ..self
}), }),
_ => Ok(self), _ => {
nu_protocol::report_error_new(
engine_state,
&ShellError::GenericError(
format!("'{key}' is not a valid URL field"),
format!("Remove '{key}' col from input record"),
Some(span),
None,
vec![],
),
);
Ok(self)
}
} }
} }
} }