aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2018-12-26 16:30:42 +0100
committerJakob Odersky <jakob@odersky.com>2018-12-26 16:38:32 +0100
commit433a83ff8e4849211ed1547d4246ef11afd059ac (patch)
treec94861b69f5e197512e2400b96f31bc2e60cec9e
downloadcodename-433a83ff8e4849211ed1547d4246ef11afd059ac.tar.gz
codename-433a83ff8e4849211ed1547d4246ef11afd059ac.tar.bz2
codename-433a83ff8e4849211ed1547d4246ef11afd059ac.zip
Initial commitv0.1.0
-rw-r--r--.gitignore1
-rw-r--r--build.sbt24
-rw-r--r--main.scala258
-rw-r--r--project/build.properties1
-rw-r--r--project/plugins.sbt2
5 files changed, 286 insertions, 0 deletions
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")