<commit_before>package moe.pizza.auth

import java.io.File

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import moe.pizza.auth.ldap.server.EmbeddedLdapServer
import moe.pizza.auth.webapp.Webapp
import scopt.OptionParser

import scala.io.Source
import scala.util.{Failure, Try}

/**
  * Created by andi on 19/02/16.
  */
object Main {
  case class RunOptions(servers: Option[ServerOptions], config: File = new File("./config.yml"))
  case class ServerOptions(ldap: Boolean = true, webinterface: Boolean = true, restapi: Boolean = false)

  val parser = new OptionParser[RunOptions]("pizza-auth") {
    head("pizza-auth-3 command line interface")
    help("help") text ("prints this usage text")
    arg[File]("<config file>") optional() action { (x, c) =>
      c.copy(config = x)
    } text ("configuration file (optional)")
    cmd("server") action { (_, c) =>
      c.copy(servers = Some(ServerOptions()))
    } text ("run pizza-auth server(s)") children(
        opt[Boolean]("ldap") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(ldap = x)))
        } text("enable the built in LDAP server"),
        opt[Boolean]("webinterface") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(webinterface = x)))
        } text("enable the main web interface"),
        opt[Boolean]("restapi") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(restapi = x)))
        } text("enable the rest API")
      )
  }


  def parseConfigFile(f: File): Try[config.ConfigFile.ConfigFile] = {
    val OM = new ObjectMapper(new YAMLFactory())
    OM.registerModule(DefaultScalaModule)
    Try {
      OM.readValue[config.ConfigFile.ConfigFile](Source.fromFile(f).mkString, classOf[config.ConfigFile.ConfigFile])
    }
  }

  def main(args: Array[String]): Unit = {
    val config = parser.parse(args, RunOptions(None))
    val configfile = parseConfigFile(config.get.config)
    configfile match {
      case Failure(f) =>
        System.err.println("Unable to read configuration file: %s".format(f))
      case _ => ()
    }
    config match {
      case Some(c) =>
        c.servers match {
          case Some(s) =>
            if (s.ldap) {
              val ldap = new EmbeddedLdapServer(
                configfile.get.embeddedldap.instancePath,
                configfile.get.embeddedldap.basedn,
                configfile.get.embeddedldap.host,
                configfile.get.embeddedldap.port
              )
              ldap.start()
            }
            if (s.webinterface) {
              import scala.concurrent.ExecutionContext.Implicits.global
              val graders = configfile.get.auth.constructGraders(configfile.get)
              val webapp = new Webapp(configfile.get, graders, 9021, null)
              webapp.start()
            }
        }
    }
  }

}<commit_msg>add some errors to Main<commit_after>package moe.pizza.auth

import java.io.File

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import moe.pizza.auth.ldap.server.EmbeddedLdapServer
import moe.pizza.auth.webapp.Webapp
import scopt.OptionParser

import scala.io.Source
import scala.util.{Failure, Try}

/**
  * Created by andi on 19/02/16.
  */
object Main {
  case class RunOptions(servers: Option[ServerOptions], config: File = new File("./config.yml"))
  case class ServerOptions(ldap: Boolean = true, webinterface: Boolean = true, restapi: Boolean = false)

  val parser = new OptionParser[RunOptions]("pizza-auth") {
    head("pizza-auth-3 command line interface")
    help("help") text ("prints this usage text")
    arg[File]("<config file>") optional() action { (x, c) =>
      c.copy(config = x)
    } text ("configuration file (optional)")
    cmd("server") action { (_, c) =>
      c.copy(servers = Some(ServerOptions()))
    } text ("run pizza-auth server(s)") children(
        opt[Boolean]("ldap") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(ldap = x)))
        } text("enable the built in LDAP server"),
        opt[Boolean]("webinterface") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(webinterface = x)))
        } text("enable the main web interface"),
        opt[Boolean]("restapi") action { (x, c) =>
          c.copy(servers = c.servers.map(_.copy(restapi = x)))
        } text("enable the rest API")
      )
  }


  def parseConfigFile(f: File): Try[config.ConfigFile.ConfigFile] = {
    val OM = new ObjectMapper(new YAMLFactory())
    OM.registerModule(DefaultScalaModule)
    Try {
      OM.readValue[config.ConfigFile.ConfigFile](Source.fromFile(f).mkString, classOf[config.ConfigFile.ConfigFile])
    }
  }

  def main(args: Array[String]): Unit = {
    val config = parser.parse(args, RunOptions(None))
    val configfile = parseConfigFile(config.get.config)
    configfile match {
      case Failure(f) =>
        System.err.println("Unable to read configuration file: %s".format(f))
      case _ => ()
    }
    config match {
      case Some(c) =>
        c.servers match {
          case Some(s) =>
            if (s.ldap) {
              val ldap = new EmbeddedLdapServer(
                configfile.get.embeddedldap.instancePath,
                configfile.get.embeddedldap.basedn,
                configfile.get.embeddedldap.host,
                configfile.get.embeddedldap.port
              )
              ldap.start()
            }
            if (s.webinterface) {
              import scala.concurrent.ExecutionContext.Implicits.global
              val graders = configfile.get.auth.constructGraders(configfile.get)
              val webapp = new Webapp(configfile.get, graders, 9021, null)
              webapp.start()
            }
          case None =>
            println("You must pick a set of servers to run")
            sys.exit(1)
        }
      case None =>
        println("Configuration couldn't be parsed")
        sys.exit(1)
    }
  }

}
{'fraction_non_alphanumeric': 0.12926948847850955, 'fraction_numerical': 0.003922209511358065, 'mean_word_length': 2.5831381733021077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6600684', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1869, 'n_words': 399}