Skip to content

Commit 566bdae

Browse files
vtjnashakayshSacha0
authored andcommitted
doc: mentions of addenv seemed lacking (JuliaLang#40539)
Co-authored-by: akaysh <[email protected]> Co-authored-by: Sacha Verweij <[email protected]> Co-authored-by: akaysh <[email protected]> Co-authored-by: Sacha Verweij <[email protected]>
1 parent d620b08 commit 566bdae

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

base/cmd.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ while changing the settings of the optional keyword arguments:
6363
array or tuple of `"var"=>val` pairs. In order to modify (rather than replace) the
6464
existing environment, initialize `env` with `copy(ENV)` and then set `env["var"]=val` as
6565
desired. To add to an environment block within a `Cmd` object without replacing all
66-
elements, use `addenv()` which will return a `Cmd` object with the updated environment.
66+
elements, use [`addenv()`](@ref) which will return a `Cmd` object with the updated environment.
6767
* `dir::AbstractString`: Specify a working directory for the command (instead
6868
of the current directory).
6969
@@ -236,9 +236,11 @@ Set environment variables to use when running the given `command`. `env` is eith
236236
dictionary mapping strings to strings, an array of strings of the form `"var=val"`, or
237237
zero or more `"var"=>val` pair arguments. In order to modify (rather than replace) the
238238
existing environment, create `env` through `copy(ENV)` and then setting `env["var"]=val`
239-
as desired, or use `addenv`.
239+
as desired, or use [`addenv`](@ref).
240240
241241
The `dir` keyword argument can be used to specify a working directory for the command.
242+
243+
See also [`Cmd`](@ref), [`addenv`](@ref), [`ENV`](@ref), [`pwd`](@ref).
242244
"""
243245
setenv(cmd::Cmd, env; dir="") = Cmd(cmd; env=byteenv(env), dir=dir)
244246
setenv(cmd::Cmd, env::Pair{<:AbstractString}...; dir="") =
@@ -248,10 +250,12 @@ setenv(cmd::Cmd; dir="") = Cmd(cmd; dir=dir)
248250
"""
249251
addenv(command::Cmd, env...; inherit::Bool = true)
250252
251-
Merge new environment mappings into the given `Cmd` object, returning a new `Cmd` object.
253+
Merge new environment mappings into the given [`Cmd`](@ref) object, returning a new `Cmd` object.
252254
Duplicate keys are replaced. If `command` does not contain any environment values set already,
253255
it inherits the current environment at time of `addenv()` call if `inherit` is `true`.
254256
257+
See also [`Cmd`](@ref), [`setenv`](@ref), [`ENV`](@ref).
258+
255259
!!! compat "Julia 1.6"
256260
This function requires Julia 1.6 or later.
257261
"""

doc/src/base/base.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ Base.ignorestatus
307307
Base.detach
308308
Base.Cmd
309309
Base.setenv
310+
Base.addenv
310311
Base.withenv
311312
Base.pipeline(::Any, ::Any, ::Any, ::Any...)
312313
Base.pipeline(::Base.AbstractCmd)

doc/src/manual/running-external-programs.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,36 @@ saturated throughput.
376376
We strongly encourage you to try all these examples to see how they work.
377377

378378
## `Cmd` Objects
379-
The syntax introduced above creates objects of type [`Cmd`](@ref). Such object may also be constructed directly:
379+
The backtick syntax create an object of type [`Cmd`](@ref). Such object may also be constructed directly from
380+
an existing `Cmd` or list of arguments:
380381

381382
```julia
382383
run(Cmd(`pwd`, dir=".."))
384+
run(Cmd(["pwd"], detach=true, ignorestatus=true))
383385
```
384386

385-
This way, they may be customized with the `dir` keyword to set the working directory,
386-
`detach` keyword to run the command in a new process group, and `env` keyword to set environment variables.
387+
This allows you to specify several aspects of the `Cmd`'s execution environment via keyword arguments. For
388+
example, the `dir` keyword provides control over the `Cmd`'s working directory:
389+
390+
```jldoctest
391+
julia> run(Cmd(`pwd`, dir="/"));
392+
/
393+
```
394+
395+
And the `env` keyword allows you to set execution environment variables:
396+
397+
```jldoctest
398+
julia> run(Cmd(`sh -c "echo foo \$HOWLONG"`, env=("HOWLONG" => "ever!",)));
399+
foo ever!
400+
```
401+
402+
See `[`Cmd`](@ref)` for additional keyword arguments. The [`setenv`](@ref) and [`addenv`](@ref) commands
403+
provide another means for replacing or adding to the `Cmd` execution environment variables, respectively:
404+
405+
```jldoctest
406+
julia> run(setenv(`sh -c "echo foo \$HOWLONG"`, ("HOWLONG" => "ever!",)));
407+
foo ever!
408+
409+
julia> run(addenv(`sh -c "echo foo \$HOWLONG"`, "HOWLONG" => "ever!"));
410+
foo ever!
411+
```

0 commit comments

Comments
 (0)