From 433a83ff8e4849211ed1547d4246ef11afd059ac Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 26 Dec 2018 16:30:42 +0100 Subject: Initial commit --- .gitignore | 1 + build.sbt | 24 +++++ main.scala | 258 +++++++++++++++++++++++++++++++++++++++++++++++ project/build.properties | 1 + project/plugins.sbt | 2 + 5 files changed, 286 insertions(+) create mode 100644 .gitignore create mode 100644 build.sbt create mode 100644 main.scala create mode 100644 project/build.properties create mode 100644 project/plugins.sbt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/build.sbt b/build.sbt new file mode 100644 index 0000000..11b057a --- /dev/null +++ b/build.sbt @@ -0,0 +1,24 @@ +enablePlugins(ScalaNativePlugin) + +scalaVersion := "2.11.12" + +version := { + import sys.process._ + ("git describe --always --dirty=-SNAPSHOT --match v[0-9].*" !!).tail.trim +} + +nativeMode := { + if (version.value.endsWith("SNAPSHOT")) "debug" else "release" +} + +sourceGenerators in Compile += Def.task { + val file = (sourceManaged in Compile).value / "BuildInfo.scala" + IO.write( + file, + s"""|package codenames + |object BuildInfo { + | val version: String = "${version.value}" + |}""".stripMargin + ) + Seq(file) +}.taskValue diff --git a/main.scala b/main.scala new file mode 100644 index 0000000..6d4879d --- /dev/null +++ b/main.scala @@ -0,0 +1,258 @@ +package codenames + +object Names { + + val adverbs = Array( + "abundantly", + "across", + "amiss", + "approximately", + "awful", + "awry", + "basic", + "beforehand", + "earnestly", + "even", + "extra", + "flat", + "forthwile", + "greatly", + "henceforth", + "hereinafter", + "hitherto", + "imminent", + "infra", + "inter", + "low", + "master", + "nearby", + "neither", + "never", + "nigh", + "nonethless", + "not", + "otherwise", + "overall", + "quick", + "real", + "soon", + "then", + "thereafter", + "throughout", + "too", + "upright", + "very" + ) + + val adjectives = Array( + "absurd", + "adjacent", + "astral", + "axial", + "azure", + "blinking", + "catchy", + "closed", + "complex", + "dark", + "extreme", + "fabulous", + "false", + "ferocious", + "flashy", + "forbidden", + "furious", + "glacial", + "grand", + "great", + "hidden", + "high", + "imaginary", + "inherent", + "intrinsic", + "jumpy", + "light", + "little", + "low", + "mellow", + "nodal", + "open", + "optimistic", + "optuse", + "patchy", + "penurious", + "perplex", + "pickled", + "polar", + "private", + "rare", + "sentient", + "serene", + "sigmoid", + "specific", + "stable", + "steep", + "top", + "true", + "ubiquitous", + "unbalanced", + "united", + "universal", + "vast", + "vindictive", + "voodoo", + "whitty", + "wide", + "wimpy", + "windy", + "xenial", + "xenolithic", + "yay", + "zillion", + "zoic" + ) + + val nouns = Array( + "aleph", + "azimuth", + "bet", + "bingo", + "cat", + "catch", + "cigar", + "clone", + "clown", + "condor", + "conjugate", + "cow", + "crow", + "dark", + "delta", + "eagle", + "echo", + "edition", + "emu", + "five", + "flume", + "fountain", + "graphite", + "gazelle", + "high", + "index", + "jack", + "jar", + "jiffy", + "joke", + "khi", + "king", + "kite", + "light", + "lima", + "loop", + "low", + "macro", + "module", + "mutton", + "nest", + "nil", + "nomenclature", + "omicron", + "one", + "open", + "ostrich", + "parcel", + "phi", + "pin", + "psi", + "pyrite", + "quartz", + "queen", + "quill", + "resource", + "rho", + "rick", + "route", + "rules", + "sentinel", + "set", + "sheep", + "sigma", + "six", + "slam", + "smoke", + "source", + "spinel", + "thunder", + "top", + "topaz", + "tulip", + "umbrella", + "unit", + "user", + "vow", + "wolf", + "xenium", + "yaw", + "yield", + "zenith", + "zero", + "zulu" + ) + +} + +object Main extends App { + + val help = + """|Usage: codename [OPTIONS...] [SPECIFICATION...] + |Generate a random codename according to a specification ("A a n" by default). + | + |Options: + | + | -h, --help show help message + | -v, --version show version information + | + |Specification: + | + | SPEC ::= { 'A' | 'a' | 'n' | SEP } + | SEP ::= char + | + |where an 'A' is replaced by a random adverb, an 'a' by an adjective and + |an 'n' by a noun. + | + |For example, the specification "A-a-n" will produce a code name such as: + |"extra-pickled-umbrella" + | + |Multiple specifications may be given, each of which will be printed on a + |separate line.""".stripMargin + + val (options, arguments) = args.partition(_.startsWith("-")) + + options foreach { + case "-h" | "--help" => + println(help) + sys.exit(0) + case "-v" | "--version" => + println(BuildInfo.version) + sys.exit(0) + case x => + System.err.println(s"Invalid option '${x}'.") + sys.exit(1) + } + + val withDefault = if (arguments.isEmpty) Array("A a n") else arguments + + def printNext(words: Array[String]) = + print(words(util.Random.nextInt(words.length))) + + withDefault foreach { arg => + arg foreach { + case 'A' => printNext(Names.adverbs) + case 'a' => printNext(Names.adjectives) + case 'n' => printNext(Names.nouns) + case other => print(other) + } + println("") + } + +} diff --git a/project/build.properties b/project/build.properties new file mode 100644 index 0000000..72f9028 --- /dev/null +++ b/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.2.7 diff --git a/project/plugins.sbt b/project/plugins.sbt new file mode 100644 index 0000000..23fd95e --- /dev/null +++ b/project/plugins.sbt @@ -0,0 +1,2 @@ +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.8") +addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1") -- cgit v1.2.3