summaryrefslogtreecommitdiff
path: root/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala
diff options
context:
space:
mode:
Diffstat (limited to 'cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala')
-rwxr-xr-xcli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala47
1 files changed, 11 insertions, 36 deletions
diff --git a/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala b/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala
index 0770ba5..bef2bc5 100755
--- a/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala
+++ b/cli/source/main/scala/com/rockymadden/stringmetric/cli/phonetic/nysiisalgorithm.scala
@@ -3,39 +3,14 @@ package com.rockymadden.stringmetric.cli.phonetic
import com.rockymadden.stringmetric.cli._
import com.rockymadden.stringmetric.phonetic.NysiisAlgorithm
-/**
- * The nysiisalgorithm [[com.rockymadden.stringmetric.cli.Command]]. Returns the phonetic representation of the passed
- * string, per the NYSIIS algorithm.
- */
-object nysiisalgorithm extends Command {
- override def main(args: Array[String]): Unit = {
- val options: OptionMap = args
-
- try
- if (options.contains('h) || options.contains('help)) {
- help()
- exit(options)
- } else if (options.contains('dashless) && (options('dashless): Array[String]).length == 1) {
- execute(options)
- exit(options)
- } else throw new IllegalArgumentException("Expected valid syntax. See --help.")
- catch { case e: Throwable => error(e, options) }
- }
-
- override def help(): Unit = {
- val ls = sys.props("line.separator")
- val tab = " "
-
- println(
- "Returns the phonetic representation of the passed string, per the NYSIIS algorithm." + ls + ls +
- "Syntax:" + ls +
- tab + "nysiisalgorithm [Options] string..." + ls + ls +
- "Options:" + ls +
- tab + "-h, --help" + ls +
- tab + tab + "Outputs description, syntax, and options."
- )
- }
-
- override def execute(options: OptionMap): Unit =
- println(NysiisAlgorithm.compute(options('dashless)).getOrElse("not computable"))
-}
+case object nysiisalgorithm extends Command(
+ (opts) =>
+ "Returns the phonetic representation of the passed string, per the NYSIIS algorithm." + Ls + Ls +
+ "Syntax:" + Ls +
+ Tab + "nysiisalgorithm [Options] string..." + Ls + Ls +
+ "Options:" + Ls +
+ Tab + "-h, --help" + Ls +
+ Tab + Tab + "Outputs description, syntax, and options.",
+ (opts) => opts.contains('dashless) && (opts('dashless): Array[String]).length == 1,
+ (opts) => NysiisAlgorithm.compute(opts('dashless)).getOrElse("not computable")
+)