Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Apr 14, 2015
1 parent c97bebf commit 413e9e7
Show file tree
Hide file tree
Showing 8 changed files with 673 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
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
13 changes: 13 additions & 0 deletions .travis.yml
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
85 changes: 85 additions & 0 deletions README.md
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.
*/
```
43 changes: 43 additions & 0 deletions build.sbt
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")
}
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 0.13.7
7 changes: 7 additions & 0 deletions project/plugins.sbt
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")
Loading

0 comments on commit 413e9e7

Please sign in to comment.