acrisci / commander-scala Goto Github PK
View Code? Open in Web Editor NEWA scalable command-line arguments parser
Home Page: http://mvnrepository.com/artifact/com.github.acrisci/commander_2.11
License: MIT License
A scalable command-line arguments parser
Home Page: http://mvnrepository.com/artifact/com.github.acrisci/commander_2.11
License: MIT License
If a program has several unnamed arguments, how would you suggest parsing them? For example, the case class below stores 5 options and 4 unnamed parameters (with defaults) that configure a program. If values for the 4 unnamed parameters are supplied they should be used, in the order supplied. Otherwise, default values should be used.
Looking at the source code, it seems that the values not associated with any option are passed along as program.args
. Is that the best way to access those values for this purpose? Some of those values might need to be converted to Ints, Longs, etc, so it would be nice to use the mechanism already in commander-scala
for doing that.
import com.github.acrisci.commander.Program
import java.io.File
abstract sealed case class Options(
consumerKey: String,
consumerSecret: String,
accessToken: String,
accessTokenSecret: String,
overWrite: Boolean = false,
tweetDirectory: File = new File("~/twitterClassifier/tweets/"),
numTweetsToCollect: Int = 100,
intervalSecs: Int = 1,
partitionsEachInterval: Int = 1
)
object Options {
def apply(args: Array[String]): Options = {
val program = new Program()
.version("2.0.0")
.option(flags="-c, --consumerKey [type]", description="Twitter OAuth Consumer Key", required=true)
.option(flags="-s, --consumerSecret [type]", description="Twitter OAuth Consumer Secret", required=true)
.option(flags="-t, --accessToken [type]", description="Twitter OAuth Access Token", required=true)
.option(flags="-v, --accessTokenSecret [type]", description="Twitter OAuth Access Token Secret", required=true)
.option(flags="-x, --overWrite", description="Overwrite data files on each run [false]", default=false)
.parse(args)
if (args.isEmpty) program.help
new Options(
consumerKey = program.consumerKey,
consumerSecret = program.consumerSecret,
accessToken = program.accessToken,
accessTokenSecret = program.accessTokenSecret,
overWrite = program.overWrite
// mandatory unnamed parameters would go here
){}
}
}
Error running the parser method on scala 2.11
I am using the package: "com.github.acrisci" % "commander_2.11" % "0.1.0" withSources()
Exception in thread "main" java.lang.NoSuchMethodError: scala.runtime.ObjectRef.create(Ljava/lang/Object;)Lscala/runtime/ObjectRef;
at com.github.acrisci.commander.Program.normalize(Program.scala:314)
at com.github.acrisci.commander.Program.parse(Program.scala:225)
at com.databricks.apps.twitterClassifier.CollectOptions$.parse(CollectOptions.scala:21)
at com.databricks.apps.twitterClassifier.Collect$.delayedEndpoint$com$databricks$apps$twitterClassifier$Collect$1(Collect.scala:11)
at com.databricks.apps.twitterClassifier.Collect$delayedInit$body.apply(Collect.scala:10)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.