-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
673 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
*.class | ||
*.log | ||
|
||
# sbt specific | ||
.cache | ||
.history | ||
.lib/ | ||
dist/* | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
project/boot/ | ||
project/plugins/project/ | ||
|
||
# Scala-IDE specific | ||
.scala_dependencies | ||
.worksheet | ||
|
||
# Intellij specific | ||
.idea/ | ||
*.ipr | ||
|
||
# OSX specific | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: scala | ||
scala: | ||
- 2.11.6 | ||
branches: | ||
only: | ||
- master | ||
- dev | ||
|
||
script: | ||
- sbt ++$TRAVIS_SCALA_VERSION clean coverage test | ||
|
||
after_success: | ||
- sbt ++$TRAVIS_SCALA_VERSION coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
| Scalargs | [![Build Status](https://travis-ci.org/elbywan/Scalargs.svg?branch=master)](https://travis-ci.org/elbywan/xtended-xml) | [![Coverage Status](https://coveralls.io/repos/elbywan/Scalargs/badge.svg)](https://coveralls.io/r/elbywan/Scalargs) | ||
=============== | ||
|
||
##Wtf ? | ||
|
||
**Scalargs** is a scala command line interface arguments parser, with a very simple DSL. | ||
It automatically validates or rejects arguments given a configuration you specify (you can specify values of a given type, mandatory arguments ...) | ||
|
||
##Installation | ||
|
||
Build it with sbt : | ||
|
||
```bash | ||
sbt publishLocal | ||
``` | ||
|
||
To play around with the library, type `sbt console`. | ||
|
||
##Usage | ||
|
||
- Specify a configuration using the DSL | ||
- Help is automatically generated and printed if the user pass -h or --help as an argument, or if the arguments are not validated | ||
- Parse the arguments as a scala map | ||
|
||
>todo : detailed usage | ||
In the meantime, you can check the tests folder for some code samples. | ||
|
||
###Import | ||
|
||
```scala | ||
import com.elbywan.scalargs.core.Scalargs._ | ||
``` | ||
|
||
###DSL | ||
|
||
*Argument syntax* | ||
- Short argument : -s | ||
- Long argument : --long | ||
|
||
*Full DSL syntax* | ||
```scala | ||
Program("Program name") [title "Title short text"] [usage "Usage text"] arguments ( | ||
argument("argument name") [empty|as[TYPE]{String => TYPE}] [mandatory|optional] [short "short argument name"] [description "Description or usage"] [perform { value => action }], | ||
shortArgument("short argument name") [empty|as[TYPE]{String => TYPE}] [mandatory|optional] [name "long argument name"] [description "Description or usage"] [perform { value => action }] | ||
(... Repeat as desired ...) | ||
) from {ARGUMENTS_ARRAY_VARIABLE} | ||
``` | ||
|
||
*Example* | ||
```scala | ||
val prog = program("Program name") title "- Just a demo" usage "Pass some arguments and watch the results" arguments ( | ||
argument("name") description "Your first or last name." mandatory() perform { x => println("Hello " + x+ "!") }, | ||
argument("age").as[Int]{_.toInt} short "a" description "Your age." mandatory() perform {x: Int => println(x)}, | ||
argument("greet") empty() description "Receive a special greeting." perform { _ => println("Hey dude !!") } | ||
) | ||
|
||
val args = prog from Array("--name", "Igor", "-a", "25") | ||
val name = args("name").getOrElse("") | ||
val age = args("age").getOrElse(0) | ||
println(s"Hey $name, are you really $age years old ?") | ||
|
||
prog from Array("--help") | ||
|
||
/* Automatically generated help * | ||
Program name - Just a demo | ||
-------------------------- | ||
Pass some arguments and watch the results | ||
= Mandatory = | ||
--name <value of type [String]> | ||
Your first or last name. | ||
--age -a <value of type [Int]> | ||
Your age. | ||
= Optional = | ||
--greet | ||
Receive a special greeting. | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name := "Scalargs" | ||
organization := "com.github.elbywan" | ||
version := "0.1-SNAPSHOT" | ||
scalaVersion := "2.11.6" | ||
|
||
val SCALATEST_VERSION = "2.2.1" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.scala-lang" % "scala-reflect" % "2.11.6", | ||
"org.scalatest" %% "scalatest" % SCALATEST_VERSION % Test | ||
) | ||
|
||
pomIncludeRepository := { _ => false } | ||
pomExtra := | ||
<url>https://github.com/elbywan/Scalargs</url> | ||
<licenses> | ||
<license> | ||
<name>GNU Gpl v3</name> | ||
<url>http://www.gnu.org/licenses/gpl.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
<scm> | ||
<url>git@github.com:elbywan/scalargs.git</url> | ||
<connection>scm:git:git@github.com:elbywan/scalargs.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>elbywan</id> | ||
<name>Julien Elbaz</name> | ||
<url>https://github.com/elbywan</url> | ||
</developer> | ||
</developers> | ||
|
||
publishArtifact in Test := false | ||
publishMavenStyle := true | ||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) | ||
Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else | ||
Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 0.13.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
logLevel := Level.Warn | ||
|
||
resolvers += Classpaths.sbtPluginReleases | ||
|
||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.0.1") | ||
|
||
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0.BETA1") |
Oops, something went wrong.