Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring + Issue #56 GitHub default branch #263

Merged
merged 5 commits into from Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/src/main/scala/giter8.scala
Expand Up @@ -17,6 +17,8 @@

package giter8

import java.io.File

class Giter8 extends xsbti.AppMain {
java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.SEVERE)

Expand All @@ -26,16 +28,17 @@ class Giter8 extends xsbti.AppMain {

/** Runner shared my main-class runner */
def run(args: Array[String]): Int = {
val helper = new JgitHelper(new Git(new JGitInteractor), G8TemplateRenderer)
val result = (args.partition { s =>
G8.Param.pattern.matcher(s).matches
} match {
case (params, options) =>
parser.parse(options, Config()).map { config =>
JgitHelper.run(config, params)
parser.parse(options, Config("")).map { config =>
helper.run(config, params, new File("."))
}.getOrElse(Left(""))
case _ => Left(parser.usage)
})
JgitHelper.cleanup()
helper.cleanup()
result.fold ({ (error: String) =>
System.err.println(s"\n$error\n")
1
Expand Down
7 changes: 4 additions & 3 deletions build.sbt
Expand Up @@ -100,14 +100,15 @@ lazy val lib = (project in file("library")).
crossScalaVersions := List(scala210, scala211, scala212),
libraryDependencies ++= Seq(
scalasti, jgit, commonsIo, plexusArchiver,
scalacheck % Test, sbtIo % Test, scalatest % Test
scalacheck % Test, sbtIo % Test, scalatest % Test,
scalamock % Test, "org.slf4j" % "slf4j-simple" % "1.7.12" % Test
) ++
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
Seq(scalaXml, parserCombinator)
case _ => Nil
})
)
})
)

def customCommands: Seq[Setting[_]] = Seq(
commands += Command.command("release") { state =>
Expand Down
215 changes: 0 additions & 215 deletions library/src/main/scala/JgitHelper.scala

This file was deleted.

7 changes: 0 additions & 7 deletions library/src/main/scala/g8.scala
Expand Up @@ -447,13 +447,6 @@ object G8 {
}
}

case class Config(
repo: String = "",
branch: Option[String] = None,
// tag: Option[String] = None,
forceOverwrite: Boolean = false
// search: Boolean = false
)
case class Path(paths: List[String]) {
def /(child: String): Path = copy(paths = paths ::: List(child))
}
Expand Down
59 changes: 59 additions & 0 deletions library/src/main/scala/giter8/ConsoleCredentialsProvider.scala
@@ -0,0 +1,59 @@
/*
* Original implementation (C) 2010-2015 Nathan Hamblen and contributors
* Adapted and extended in 2016 by foundweekends project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package giter8

import org.eclipse.jgit.transport.{CredentialItem, CredentialsProvider, URIish}

object ConsoleCredentialsProvider extends CredentialsProvider {

def isInteractive = true

def supports(items: CredentialItem*) = true

def get(uri: URIish, items: CredentialItem*): Boolean = {
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))

case i: CredentialItem.StringType if uri.getScheme == "ssh" =>
val password = String.valueOf(System.console.readPassword("%s: ", i.getPromptText))
i.setValue(password)
}
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)
}
}
}