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

com.ebiznext.comet.schema.generator.SchemaGenConfig.scala Maven / Gradle / Ivy

There is a newer version: 0.2.6
Show newest version
/*
 *
 *  * Licensed to the Apache Software Foundation (ASF) under one or more
 *  * contributor license agreements.  See the NOTICE file distributed with
 *  * this work for additional information regarding copyright ownership.
 *  * The ASF licenses this file to You 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 com.ebiznext.comet.schema.generator

import buildinfo.BuildInfo
import com.ebiznext.comet.utils.CliConfig
import scopt.OParser

/**
  * @param files List of Excel files
  * @param encryption Should pre & post encryption YAML be generated ?
  * @param delimiter : Delimiter to use on generated CSV file after pre-encryption.
  * @param privacy What privacy policies are to be applied at the pre-encrypt step ? All by default.
  */
case class SchemaGenConfig(
  files: Seq[String] = Nil,
  encryption: Boolean = true,
  delimiter: Option[String] = None,
  privacy: Seq[String] = Nil,
  outputPath: Option[String] = None
)

object SchemaGenConfig extends CliConfig[SchemaGenConfig] {

  val parser: OParser[Unit, SchemaGenConfig] = {
    val builder = OParser.builder[SchemaGenConfig]
    import builder._
    OParser.sequence(
      programName("comet"),
      head("comet", BuildInfo.version),
      opt[Seq[String]]("files")
        .action((x, c) => c.copy(files = x))
        .required()
        .text("List of Excel files describing Domains & Schemas"),
      opt[Boolean]("encryption")
        .action((x, c) => c.copy(encryption = x))
        .required()
        .text("If true generate pre and post encryption YML"),
      opt[String]("delimiter")
        .action((x, c) => c.copy(delimiter = Some(x)))
        .optional()
        .text("CSV delimiter to use in post-encrypt YML."),
      opt[Seq[String]]("privacy")
        .action((x, c) => c.copy(privacy = x map (_.toUpperCase)))
        .optional()
        .text("""What privacy policies should be applied in the pre-encryption phase ?
            | All privacy policies are applied by default.""".stripMargin),
      opt[Option[String]]("outputPath")
        .action((x, c) => c.copy(outputPath = x))
        .optional()
        .text("""Path for saving the resulting YAML file(s).
            | COMET domains path is used by default.""".stripMargin)
    )
  }

  /**
    * @param args args list passed from command line
    * @return Option of case class SchemaGenConfig.
    */
  def parse(args: Seq[String]): Option[SchemaGenConfig] =
    OParser.parse(parser, args, SchemaGenConfig())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy