diff --git a/base/deprecated.jl b/base/deprecated.jl index 5e63afcff4a1e..32cd46ecd5f49 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1615,6 +1615,16 @@ function SymTridiagonal(dv::AbstractVector{T}, ev::AbstractVector{S}) where {T,S SymTridiagonal(convert(Vector{R}, dv), convert(Vector{R}, ev)) end +# PR #23092 +@eval LibGit2 begin + function prompt(msg::AbstractString; default::AbstractString="", password::Bool=false) + Base.depwarn(string( + "`LibGit2.prompt(msg::AbstractString; default::AbstractString=\"\", password::Bool=false)` is deprecated, use ", + "`get(Base.prompt(msg, default=default, password=password), \"\")` instead."), :prompt) + Base.get(Base.prompt(msg, default=default, password=password), "") + end +end + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index 8d4f69f7c6505..5ecbacc4d6c9b 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -78,7 +78,7 @@ function authenticate_ssh(creds::SSHCredentials, libgit2credptr::Ptr{Ptr{Void}}, if !isusedcreds username = uname else - response = prompt("Username for '$schema$host'", default=uname) + response = Base.prompt("Username for '$schema$host'", default=uname) isnull(response) && return user_abort() username = unsafe_get(response) end @@ -94,7 +94,7 @@ function authenticate_ssh(creds::SSHCredentials, libgit2credptr::Ptr{Ptr{Void}}, if isempty(keydefpath) && isfile(defaultkeydefpath) keydefpath = defaultkeydefpath else - response = prompt("Private key location for '$schema$username@$host'", + response = Base.prompt("Private key location for '$schema$username@$host'", default=keydefpath) isnull(response) && return user_abort() keydefpath = unsafe_get(response) @@ -119,7 +119,7 @@ function authenticate_ssh(creds::SSHCredentials, libgit2credptr::Ptr{Ptr{Void}}, keydefpath = privatekey*".pub" end if !isfile(keydefpath) - response = prompt("Public key location for '$schema$username@$host'", + response = Base.prompt("Public key location for '$schema$username@$host'", default=keydefpath) isnull(response) && return user_abort() keydefpath = unsafe_get(response) @@ -140,7 +140,7 @@ function authenticate_ssh(creds::SSHCredentials, libgit2credptr::Ptr{Ptr{Void}}, isnull(response) && return user_abort() passdef = unsafe_get(response)[2] else - response = prompt("Passphrase for $privatekey", password=true) + response = Base.prompt("Passphrase for $privatekey", password=true) isnull(response) && return user_abort() passdef = unsafe_get(response) isempty(passdef) && return user_abort() # Ambiguous if EOF or newline @@ -179,12 +179,12 @@ function authenticate_userpass(creds::UserPasswordCredentials, libgit2credptr::P username, userpass = unsafe_get(response) end elseif isusedcreds - response = prompt("Username for '$schema$host'", + response = Base.prompt("Username for '$schema$host'", default=isempty(username) ? urlusername : username) isnull(response) && return user_abort() username = unsafe_get(response) - response = prompt("Password for '$schema$username@$host'", password=true) + response = Base.prompt("Password for '$schema$username@$host'", password=true) isnull(response) && return user_abort() userpass = unsafe_get(response) isempty(userpass) && return user_abort() # Ambiguous if EOF or newline diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index f3ebe68d129c9..7aef29151b828 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -31,24 +31,6 @@ isset(val::Integer, flag::Integer) = (val & flag == flag) reset(val::Integer, flag::Integer) = (val &= ~flag) toggle(val::Integer, flag::Integer) = (val |= flag) -function prompt(msg::AbstractString; default::AbstractString="", password::Bool=false) - if Sys.iswindows() && password - error("Command line prompt not supported for password entry on windows. Use winprompt instead") - end - msg = !isempty(default) ? msg*" [$default]:" : msg*":" - uinput = if password - Base.getpass(msg) # Automatically chomps. We cannot tell EOF from '\n'. - else - print(msg) - readline(chomp=false) - end - if !password - isempty(uinput) && return Nullable{String}() # Encountered EOF - uinput = chomp(uinput) - end - Nullable{String}(isempty(uinput) ? default : uinput) -end - function features() feat = ccall((:git_libgit2_features, :libgit2), Cint, ()) res = Consts.GIT_FEATURE[] diff --git a/base/util.jl b/base/util.jl index 413b304fb0ab4..3edd92a861675 100644 --- a/base/util.jl +++ b/base/util.jl @@ -672,6 +672,32 @@ else getpass(prompt::AbstractString) = unsafe_string(ccall(:getpass, Cstring, (Cstring,), prompt)) end +""" + prompt(message; default="", password=false) -> Nullable{String} + +Displays the `message` then waits for user input. Input is terminated when a newline (\\n) +is encountered or EOF (^D) character is entered on a blank line. If a `default` is provided +then the user can enter just a newline character to select the `default`. Alternatively, +when the `password` keyword is `true` the characters entered by the user will not be +displayed. +""" +function prompt(message::AbstractString; default::AbstractString="", password::Bool=false) + if Sys.iswindows() && password + error("Command line prompt not supported for password entry on windows. Use `Base.winprompt` instead") + end + msg = !isempty(default) ? "$message [$default]:" : "$message:" + if password + # `getpass` automatically chomps. We cannot tell an EOF from a '\n'. + uinput = getpass(msg) + else + print(msg) + uinput = readline(chomp=false) + isempty(uinput) && return Nullable{String}() # Encountered an EOF + uinput = chomp(uinput) + end + Nullable{String}(isempty(uinput) ? default : uinput) +end + # Windows authentication prompt if Sys.iswindows() struct CREDUI_INFO