Skip to content

Commit

Permalink
Fix fsprojects#1722: added a username and password option scripting
Browse files Browse the repository at this point in the history
This allows add-credentials to supply username and password from the
command line.
  • Loading branch information
pauxus committed Jun 16, 2016
1 parent f24271b commit 9ff1857
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/Paket.Core/ConfigFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ let AddToken (source, token) =
| None -> ()
}

let askAndAddAuth (source : string) (username : string) =
let askAndAddAuth (source : string) (username : string) (password : string) =
let username =
if username = "" then
Console.Write "Username: "
Console.ReadLine()
else
username

let password = readPassword "Password: "
let password =
if password = "" then
readPassword "Password: "
else
password
AddCredentials (source, username, password)
4 changes: 2 additions & 2 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ type Dependencies(dependenciesFileName: string) =
projectName, installAfter))

/// Adds credentials for a Nuget feed
member this.AddCredentials(source: string, username: string) : unit =
member this.AddCredentials(source: string, username: string, password : string) : unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> ConfigFile.askAndAddAuth source username |> returnOrFail )
fun () -> ConfigFile.askAndAddAuth source username password |> returnOrFail )

/// Adds a token for a source
member this.AddToken(source : string, token : string) : unit =
Expand Down
4 changes: 4 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ with
type ConfigArgs =
| [<CustomCommandLine("add-credentials")>] AddCredentials of string
| [<CustomCommandLine("add-token")>] AddToken of string * string
| Username of string
| Password of string
with
interface IArgParserTemplate with
member this.Usage =
match this with
| AddCredentials(_) -> "Add credentials for the specified NuGet feed."
| AddToken(_) -> "Add token for the specified source."
| Username(_) -> "Provide a username (for scripting)"
| Password(_) -> "provide a password on the commandline (for scripting)"

type ConvertFromNugetArgs =
| [<AltCommandLine("-f")>] Force
Expand Down
5 changes: 3 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
<DocumentationFile>
</DocumentationFile>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartAction>Project</StartAction>
<StartProgram>D:\develop\github\Paket\bin\paket.exe</StartProgram>
<StartAction>Program</StartAction>
<StartArguments>add-credentials http://blub --batch blub bli</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
9 changes: 3 additions & 6 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@ let config (results : ParseResults<_>) =
| true, _ ->
let args = results.GetResults <@ ConfigArgs.AddCredentials @>
let source = args.Item 0
let username =
if(args.Length > 1) then
args.Item 1
else
""
Dependencies.Locate().AddCredentials(source, username)
let username, password = results.GetResult (<@ ConfigArgs.Username @>, ""), results.GetResult (<@ ConfigArgs.Password @>, "")

Dependencies.Locate().AddCredentials(source, username, password)
| _, true ->
let args = results.GetResults <@ ConfigArgs.AddToken @>
let source, token = args.Item 0
Expand Down

0 comments on commit 9ff1857

Please sign in to comment.