<commit_before>package com.ldaniels528.verify.modules

/**
 * Represents a Shell command
 * @author <NAME> <<EMAIL>>
 */
case class Command(module: Module,
                   name: String,
                   fx: Seq[String] => Any,
                   params: CommandParameters,
                   help: String = "",
                   promptAware: Boolean = false,
                   undocumented: Boolean = false) {

  def prototype: String = params.prototypeOf(this)

  override def toString = prototype

}

/**
 * Represents the parameters of a Shell command
 * @author <NAME> <<EMAIL>>
 */
sealed trait CommandParameters {

  def checkArgs(command: Command, args: Seq[String]): Unit

  def prototypeOf(command: Command): String

}

/**
 * Simple Command Parameters
 * @param required the sequence of required parameters
 * @param optional the sequence of optional parameters
 * @author <NAME> <<EMAIL>>
 */
case class SimpleParams(required: Seq[String] = Seq.empty, optional: Seq[String] = Seq.empty)
  extends CommandParameters {

  override def checkArgs(command: Command, args: Seq[String]) {
    if (args.length < required.size || args.length > required.size + optional.size) {
      throw new IllegalArgumentException(s"Usage: ${command.prototype}")
    }
  }

  override def prototypeOf(command: Command): String = {
    val requiredParams = (required map (s => s"<$s>")).mkString(" ")
    val optionalParams = (optional map (s => s"<$s>")).mkString(" ")
    s"${command.name} $requiredParams ${if (optionalParams.nonEmpty) s"[$optionalParams]" else ""}"
  }

}<commit_msg>added a Unix-Style Command Parameter class<commit_after>package com.ldaniels528.verify.modules

/**
 * Represents a Shell command
 * @author <NAME> <<EMAIL>>
 */
case class Command(module: Module,
                   name: String,
                   fx: Seq[String] => Any,
                   params: CommandParameters,
                   help: String = "",
                   promptAware: Boolean = false,
                   undocumented: Boolean = false) {

  def prototype: String = params.prototypeOf(this)

  override def toString = prototype

}

/**
 * Represents the parameters of a Shell command
 * @author <NAME> <<EMAIL>>
 */
sealed trait CommandParameters {

  def checkArgs(command: Command, args: Seq[String]): Unit

  def prototypeOf(command: Command): String

}

/**
 * Simple Command Parameters
 * @param required the sequence of required parameters
 * @param optional the sequence of optional parameters
 * @author <NAME> <<EMAIL>>
 */
case class SimpleParams(required: Seq[String] = Seq.empty, optional: Seq[String] = Seq.empty)
  extends CommandParameters {

  override def checkArgs(command: Command, args: Seq[String]) {
    if (args.length < required.size || args.length > required.size + optional.size) {
      throw new IllegalArgumentException(s"Usage: ${command.prototype}")
    }
  }

  override def prototypeOf(command: Command): String = {
    val requiredParams = (required map (s => s"<$s>")).mkString(" ")
    val optionalParams = (optional map (s => s"<$s>")).mkString(" ")
    s"${command.name} $requiredParams ${if (optionalParams.nonEmpty) s"[$optionalParams]" else ""}"
  }

}

/**
 * Unix-Style Command Parameters
 * @param flags the given collection of flag tuple
 * @author <NAME> <<EMAIL>>
 */
case class UnixLikeParams(required: Seq[String] = Nil, flags: Seq[(String, String)] = Nil)
  extends CommandParameters[List[(String, List[String])]] {

  override def checkArgs(command: Command, args: Seq[String]) = ()

  override def prototypeOf(command: Command): String = {
    val params = flags.foldLeft[List[String]](Nil) { case (list, (flag, desc)) =>
      desc :: flag :: list
    }
    params.reverse.mkString(" ")
  }

  override def transform(args: Seq[String]): List[(String, List[String])] = parseArgs(args)

}
{'fraction_non_alphanumeric': 0.13434001562093204, 'fraction_numerical': 0.0015620932048945586, 'mean_word_length': 3.3609534619750283, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1460724', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1082, 'n_words': 316}