All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ends.giter8.giter8_2.11.0.12.0-M2.source-code.giter8.scala Maven / Gradle / Ivy

/*
 * 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 java.io.File

import scopt.OptionParser

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

  /** The launched conscript entry point */
  def run(config: xsbti.AppConfiguration): Exit =
    new Exit(Giter8.run(config.arguments))

  /** Runner shared my main-class runner */
  def run(args: Array[String], baseDirectory: File): 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 =>
            helper.run(config, params, baseDirectory)
          }
          .getOrElse(Left(""))
      case _ => Left(parser.usage)
    })
    helper.cleanup()
    result.fold({ (error: String) =>
      System.err.println(s"\n$error\n")
      1
    }, { (message: String) =>
      println("\n%s\n" format message)
      0
    })
  }

  def run(args: Array[String]): Int = run(args, new File(".").getAbsoluteFile)

  val parser: OptionParser[Config] = new scopt.OptionParser[Config]("g8") {

    head("g8", giter8.BuildInfo.version)

    arg[String]("