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