Skip to content

Commit 0faaca9

Browse files
authored
Add the optional modify_environment kwarg to the authenticate(server::AbstractString) method
1 parent 87517b4 commit 0faaca9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/PkgAuthentication.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ function _assert_pkg_server_env_var_is_set()
3131
end
3232

3333
"""
34-
authenticate(server::AbstractString)
34+
authenticate(server::AbstractString; kwargs...)
3535
3636
Starts interactive (blocking) browser-based Pkg server authentication for the Pkg
3737
server specified by `server`. Also sets the `$(pkg_server_env_var_name)` environment
3838
variable to `server`.
3939
4040
`server` must be the URL of a valid Pkg server.
4141
42+
## Keyword arguments
43+
- `modify_environment::Bool = true`: Set the `$(pkg_server_env_var_name)` environment variable to server.
44+
4245
## Example usage
4346
4447
```julia
@@ -50,13 +53,20 @@ function authenticate(
5053
auth_suffix::Union{String, Nothing} = nothing,
5154
force::Union{Bool, Nothing} = nothing,
5255
tries::Union{Integer, Nothing} = nothing,
56+
modify_environment::Bool = true,
5357
)::Union{Success, Failure}
54-
ENV[pkg_server_env_var_name] = server
55-
authenticate(;
56-
auth_suffix = auth_suffix,
57-
force = force,
58-
tries = tries,
59-
)
58+
if modify_environment
59+
ENV[pkg_server_env_var_name] = server
60+
end
61+
# Even if `modify_environment` is `false`, we still need to set the environment
62+
# variable for the duration of the `authenticate` call.
63+
withenv(pkg_server_env_var_name => server)
64+
authenticate(;
65+
auth_suffix = auth_suffix,
66+
force = force,
67+
tries = tries,
68+
)
69+
end
6070
end
6171

6272
"""

0 commit comments

Comments
 (0)