Skip to content

Commit

Permalink
prompt for credentials if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
thirstycrow committed Sep 4, 2014
1 parent d25e6ff commit de3b084
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/src/main/scala/apply.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package giter8

import org.eclipse.jgit.transport._

trait Apply { self: Giter8 =>
import java.io.File
import org.apache.commons.io.FileUtils
Expand Down Expand Up @@ -84,6 +86,7 @@ trait Apply { self: Giter8 =>
val cmd = Git.cloneRepository()
.setURI(repo)
.setDirectory(tempdir)
.setCredentialsProvider(ConsoleCredentialsProvider)

val branchName = config.branch.map("refs/heads/" + _)
for(b <- branchName)
Expand Down Expand Up @@ -112,3 +115,38 @@ trait Apply { self: Giter8 =>
}
}
}

object ConsoleCredentialsProvider extends CredentialsProvider {

def isInteractive = true

def supports(items: CredentialItem*) = true

def get(uri: URIish, items: CredentialItem*) = {
items foreach {
case i: CredentialItem.Username =>
val username = System.console.readLine("%s: ", i.getPromptText)
i.setValue(username)

case i: CredentialItem.Password =>
val password = System.console.readPassword("%s: ", i.getPromptText)
i.setValueNoCopy(password)

case i: CredentialItem.InformationalMessage =>
System.console.printf("%s\n", i.getPromptText)

case i: CredentialItem.YesNoType =>
i.setValue(askYesNo(i.getPromptText))
}
true
}

@scala.annotation.tailrec
def askYesNo(prompt: String): Boolean = {
System.console.readLine("%s: ", prompt).trim.toLowerCase match {
case "yes" => true
case "no" => false
case _ => askYesNo(prompt)
}
}
}

1 comment on commit de3b084

@eskatos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of us badly need this to be released! See #94 & #117.

Please sign in to comment.