Skip to content

Improve with-env robustness#12523

Merged
WindSoilder merged 11 commits intonushell:mainfrom
sholderbach:with-env-work
Apr 16, 2024
Merged

Improve with-env robustness#12523
WindSoilder merged 11 commits intonushell:mainfrom
sholderbach:with-env-work

Conversation

@sholderbach
Copy link
Copy Markdown
Member

@sholderbach sholderbach commented Apr 15, 2024

Description

Work for #7149

  • Error with-env given uneven count in list form
  • Fix with-env CantConvert to record
  • Error with-env when given protected env vars
  • Deprecate list/table input of vars to with-env
  • Remove examples for deprecated input

User-Facing Changes

Deprecation of the following forms

> with-env [MYENV "my env value"] { $env.MYENV }
my env value

> with-env [X Y W Z] { $env.X }
Y

> with-env [[X W]; [Y Z]] { $env.W }
Z

recommended standardized form

# Set by key-value record
> with-env {X: "Y", W: "Z"} { [$env.X $env.W] }
╭───┬───╮
│ 0 │ Y │
│ 1 │ Z │
╰───┴───╯

(Side effect) Repeated definitions in an env shorthand are now disallowed

> FOO=bar FOO=baz $env
Error: nu::shell::column_defined_twice

  × Record field or table column used twice: FOO
   ╭─[entry #1:1:1]
 1 │ FOO=bar FOO=baz $env
   · ─┬─     ─┬─
   ·  │       ╰── field redefined here
   ·  ╰── field first defined here
   ╰────

`CantConvert` is probably not the most appropriate, but semantically we
try to convert the mess to a record.
Same behavior as `$env.PROTECTED = ...` assignment evaluation or
`load-env`
Record is more readable and explicit although slightly more work to
generate in code than a list
@sholderbach sholderbach added the category:deprecation Related to the deprecation of commands/features/options label Apr 15, 2024
`FOO=bar command` syntax gets desugared in the parser to a `with-env`
call.

Thus migrate to the recommended record form.
This was otherwise traversing the engine state for the definition of
`with-env` even if it is not needed here. May improve performance
slightly (if llvm did not come to the conclusion that this had no
side-effects and could reorder)
@sholderbach sholderbach added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Apr 15, 2024
Now disallowed

```
FOO=bar FOO=baz $env
```
@sholderbach sholderbach marked this pull request as ready for review April 15, 2024 19:28
@IanManske IanManske added notes:mention Include the release notes summary in the "Hall of Fame" section deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way and removed notes:mention Include the release notes summary in the "Hall of Fame" section labels Apr 15, 2024
Copy link
Copy Markdown
Member

@IanManske IanManske left a comment

Choose a reason for hiding this comment

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

Nice, looks good to me.

Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@WindSoilder WindSoilder merged commit c9e9b13 into nushell:main Apr 16, 2024
@sholderbach sholderbach deleted the with-env-work branch April 16, 2024 21:51
@hustcer hustcer added this to the v0.93.0 milestone Apr 17, 2024
WindSoilder pushed a commit that referenced this pull request May 23, 2024
# Description
Following from #12523, this PR removes support for lists of environments
variables in the `with-env` command. Rather, only records will be
supported now.

# After Submitting
Update examples using the list form in the docs and book.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:deprecation Related to the deprecation of commands/features/options deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants