Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename def-env to def --env #1155

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions book/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ If you have more than one environment variable you'd like to set, you can use [`
These are defined to be active only temporarily for a duration of executing a code block.
See [Single-use environment variables](environment.md#single-use-environment-variables) for details.

### Calling a command defined with [`def-env`](/commands/docs/def-env.md)
### Calling a command defined with [`def --env`](/commands/docs/def.md)

See [Defining environment from custom commands](environment.md#defining-environment-from-custom-commands) for details.

Expand Down Expand Up @@ -167,10 +167,10 @@ $env.FOO = 'BAR'
## Defining environment from custom commands

Due to the scoping rules, any environment variables defined inside a custom command will only exist inside the command's scope.
However, a command defined as [`def-env`](/commands/docs/def-env.md) instead of [`def`](/commands/docs/def.md) (it applies also to [`export def`](/commands/docs/export_def.md), see [Modules](modules.md)) will preserve the environment on the caller's side:
However, a command defined as [`def --env`](/commands/docs/def.md) instead of [`def`](/commands/docs/def.md) (it applies also to [`export def`](/commands/docs/export_def.md), see [Modules](modules.md)) will preserve the environment on the caller's side:

```nu
> def-env foo [] {
> def --env foo [] {
$env.FOO = 'BAR'
}

Expand Down
2 changes: 1 addition & 1 deletion book/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ $env.config = ($env.config | upsert hooks {
## Changing Environment

One feature of the hooks is that they preserve the environment.
Environment variables defined inside the hook **block** will be preserved in a similar way as [`def-env`](environment.md#defining-environment-from-custom-commands).
Environment variables defined inside the hook **block** will be preserved in a similar way as [`def --env`](environment.md#defining-environment-from-custom-commands).
You can test it with the following example:

```nu
Expand Down
6 changes: 3 additions & 3 deletions book/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In Nushell, creating a module and importing definitions from a module are two di

You can define the following things inside a module:

- Commands\* (`def`, `def-env`)
- Commands\* (`def`)
- Aliases (`alias`)
- Known externals\* (`extern`)
- Submodules (`module`)
Expand Down Expand Up @@ -186,7 +186,7 @@ The `main` is exported only when

Importing definitions selectively (`use greetings.nu hello` or `use greetings.nu [hello hi]`) does not define the `greetings` command from `main`. You can, however, selectively import `main` using `use greetings main` (or `[main]`) which defines _only_ the `greetings` command without pulling in `hello` or `hi`.

Apart from commands (`def`, `def-env`), known externals (`extern`) can also be named `main`.
Apart from commands (`def`, `def --env`), known externals (`extern`) can also be named `main`.

## Submodules and subcommands

Expand Down Expand Up @@ -469,7 +469,7 @@ Now you've set up a directory where you can put your completion files and you sh

### Setting environment + aliases (conda style)

`def-env` commands, `export-env` block and aliases can be used to dynamically manipulate "virtual environments" (a concept well known from Python).
`def --env` commands, `export-env` block and aliases can be used to dynamically manipulate "virtual environments" (a concept well known from Python).

We use it in our official virtualenv integration https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu

Expand Down
4 changes: 2 additions & 2 deletions book/thinking_in_nu.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ In practice, this lets you write some concise code for working with subdirectori

The [`cd`](/commands/docs/cd.md) command changes the `PWD` environment variables, and this variable change does not escape the block, allowing each iteration to start from the current directory and enter the next subdirectory.

Having the environment scoped like this makes commands more predictable, easier to read, and when the time comes, easier to debug. Nushell also provides helper commands like [`def-env`](/commands/docs/def-env.md), [`load-env`](/commands/docs/load-env.md), as convenient ways of doing batches of updates to the environment.
Having the environment scoped like this makes commands more predictable, easier to read, and when the time comes, easier to debug. Nushell also provides helper commands like [`def --env`](/commands/docs/def.md), [`load-env`](/commands/docs/load-env.md), as convenient ways of doing batches of updates to the environment.

_There is one exception here, where [`def-env`](/commands/docs/def-env.md) allows you to create a command that participates in the caller's environment._
_There is one exception here, where [`def --env`](/commands/docs/def.md) allows you to create a command that participates in the caller's environment._

**Thinking in Nushell:** - The coding best practice of no global mutable variables extends to the environment in Nushell. Using the built-in helper commands will let you more easily work with the environment in Nushell. Taking advantage of the fact that environments are scoped to blocks can also help you write more concise scripts and interact with external commands without adding things into a global environment you don't need.
6 changes: 3 additions & 3 deletions de/book/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Diese besteht aus name/value Paaren, welche alle auf einmal geladen werden:
Dies sind Variablen, welche nur innerhalb eines Blocks gültig sind.
Siehe [Einmalig verwendete Umgebungsvariablen](environment.md#single-use-environment-variables) für Details.

### Aufruf eines Befehls mit [`def-env`](/commands/docs/def-env.md)
### Aufruf eines Befehls mit [`def --env`](/commands/docs/def.md)

Siehe [Definiere Umgebung aus eigenen Befehlen](environment.md#defining-environment-from-custom-commands) für Details.

Expand Down Expand Up @@ -119,11 +119,11 @@ $env.FOO = 'BAR'
## Definition einer Umgebungsvariablen für selbst definierten Befehl

Aufgrund der Gültigkeitsregeln ist eine Umgebungsvariable, welche innerhalb eines selbstdefinierten Befehls gesetzt ist, auch nur in dessen Block gültig.
Wird sie jedoch mit [`dev-env`](/commands/docs/def-env.md) anstatt [`def`](/commands/docs/def.md) gesetzt, so wird sie beim verlassen des Blocks erhalten bleiben.
Wird sie jedoch mit [`def --env`](/commands/docs/def.md) anstatt [`def`](/commands/docs/def.md) gesetzt, so wird sie beim verlassen des Blocks erhalten bleiben.
(Gilt auch für `export def`, siehe [Modules](modules.md))

```
> def-env foo [] {
> def --env foo [] {
$env.FOO = 'BAR'
}

Expand Down
2 changes: 1 addition & 1 deletion de/book/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $env.config = ($env.config | upsert hooks {
## Changing Environment

Eine Besonderheit der Hooks ist, dass sie die Umgebung bewahren.
Umgebungsvariablen im Hook **Block** werden in ähnlicher Weise wie [`def-env`](environment.md#defining-environment-from-custom-commands) erhalten.
Umgebungsvariablen im Hook **Block** werden in ähnlicher Weise wie [`def --env`](environment.md#defining-environment-from-custom-commands) erhalten.
Folgendes Beispiel zeigt dies:

```
Expand Down
4 changes: 2 additions & 2 deletions de/book/thinking_in_nushell.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ Der `cd` Befehl wechselt die `PWD` Umgebungsvariable, was wiederum nur für den
Jede Iteration startet deshalb wieder im gleichen Start-Verzeichnis.

Mit diesen Gültigkeitsbereichen, lassen sich besser vorhersehbare Befehle schreiben, welche einfacher zu lesen sind. Es erleichtert ebenfalls die Fehlersuche.
Nushell stellt auch Hilfsbefehle zur Verfügung wie [`def-env`](/commands/docs/def-env.md), [`load-env`](/commands/docs/load-env.md)), als einfachen Weg ganze Stapel von Umgebungsupdates durch zu führen.
Nushell stellt auch Hilfsbefehle zur Verfügung wie [`def --env`](/commands/docs/def.md), [`load-env`](/commands/docs/load-env.md)), als einfachen Weg ganze Stapel von Umgebungsupdates durch zu führen.

`*` - Es gibt hier eine Ausnahme. [`def-env`](/commands/docs/def-env.md) erlaubt es einem Befehl an der Umgebung teilzuhaben, von der aus er aufgerufen wurde.
`*` - Es gibt hier eine Ausnahme. [`def --env`](/commands/docs/def.md) erlaubt es einem Befehl an der Umgebung teilzuhaben, von der aus er aufgerufen wurde.

**Denken in Nushell** - Das bewährte Verfahren keine globalen veränderlichen Variablen zu benutzen, erweitert sich in Nushell auf die Umgebung.
Die eingebauten Hilfs-Befehle helfen dabei, einfacher mit der Umgebung zu arbeiten.
Expand Down
6 changes: 3 additions & 3 deletions zh-CN/book/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $env.PATH = ($env.PATH | prepend '/path/you/want/to/add')
这些变量被定义为只在执行代码块的过程中临时有效。
详情请看 [一次性环境变量](environment.md#一次性环境变量) 。

### 调用[`def-env`](/commands/docs/def-env.md)定义的命令
### 调用[`def --env`](/commands/docs/def.md)定义的命令

详情见 [从自定义命令中定义环境](environment.md#从自定义命令中定义环境变量)。

Expand Down Expand Up @@ -127,10 +127,10 @@ $env.FOO = 'BAR'
## 从自定义命令中定义环境变量

由于作用域规则,在自定义命令中定义的任何环境变量都只存在于该命令的作用域内。
然而,用[`def-env`](/commands/docs/def-env.md)而不是[`def`](/commands/docs/def.md)定义的命令(它也适用于`export def`,见 [模块](modules.md))将在调用者一方保留环境设置:
然而,用[`def --env`](/commands/docs/def.md)而不是[`def`](/commands/docs/def.md)定义的命令(它也适用于`export def`,见 [模块](modules.md))将在调用者一方保留环境设置:

```nu
> def-env foo [] {
> def --env foo [] {
$env.FOO = 'BAR'
}

Expand Down
2 changes: 1 addition & 1 deletion zh-CN/book/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $env.config = ($env.config | upsert hooks {
## 修改环境变量

钩子的一个特点是它们保留了环境。
在钩子**代码块**内定义的环境变量将以类似于 [`def-env`](environment.md#从自定义命令中定义环境变量) 的方式被保留下来。
在钩子**代码块**内定义的环境变量将以类似于 [`def --env`](environment.md#从自定义命令中定义环境变量) 的方式被保留下来。
你可以用下面的例子测试一下:

```nu
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/book/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export def hi [where: string] {

我们在 `greetings` 模块中定义了 `hello` 和 `hi` 两个自定义命令。`export`关键字使得以后可以从模块中导入该命令。

与[`def`](/commands/docs/def.md)类似,也可以用`export`关键字标记[`def-env`](/commands/docs/def-env.md)(你可以在[环境](environment.md)章节中了解更多关于[`def-env`](/commands/docs/def-env.md)的信息)。
与[`def`](/commands/docs/def.md)类似,也可以用`export`关键字标记[`def --env`](/commands/docs/def.md)(你可以在[环境](environment.md)章节中了解更多关于[`def --env`](/commands/docs/def.md)的信息)。

## 使用模块

Expand Down Expand Up @@ -199,7 +199,7 @@ hello Arthur, King of the Britons!
下面是所有你可以导出的列表:

- `export def` - 导出一个自定义命令
- `export def-env` - 导出一个自定义环境命令
- `export def --env` - 导出一个自定义环境命令
- `export env` - 导出一个环境变量
- `export alias` - 导出一个别名
- `export extern` - 导出一个已知外部命令的定义
Expand Down
4 changes: 2 additions & 2 deletions zh-CN/book/thinking_in_nu.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ Nushell 从编译型语言中获得了很多设计灵感,其中一个是语言

`cd`命令改变了`PWD`环境变量,这个变量的改变只在当前代码块有效,如此即可允许每次迭代都从当前目录开始,进入下一个子目录。

环境变量具有作用域使命令更可预测,更容易阅读,必要时也更容易调试。Nushell 还提供了一些辅助命令,如[`def-env`](/commands/docs/def-env.md)、[`load-env`](/commands/docs/load-env.md),作为对环境变量进行批量更新的辅助方法。
环境变量具有作用域使命令更可预测,更容易阅读,必要时也更容易调试。Nushell 还提供了一些辅助命令,如[`def --env`](/commands/docs/def.md)、[`load-env`](/commands/docs/load-env.md),作为对环境变量进行批量更新的辅助方法。

`*` - 这里有一个例外,[`def-env`](/commands/docs/def-env.md)允许你创建一个可以修改并保留调用者环境的命令
`*` - 这里有一个例外,[`def --env`](/commands/docs/def.md)允许你创建一个可以修改并保留调用者环境的命令

**以 Nushell 的方式思考:** 在 Nushell 中,没有全局可修改变量的编码最佳实践延伸到了环境变量。使用内置的辅助命令可以让你更容易地处理 Nushell 中的环境变量问题。利用环境变量对代码块具有作用范围这一事实,也可以帮助你写出更简洁的脚本,并与外部命令互动,而不需要在全局环境中添加你不需要的东西。