Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for #20 - Add Support for CLI options #21

Closed
wants to merge 3 commits into from

2 participants

@randomcoder

A simple fix to extract additional command line options from the arguments passed to the cucumber task that are not already handled by the plugin.

Adds support for:

  • --dry-run, -d
  • --strict, -s
  • --monochrone, -m

Also updated version for Scala 2.10 to the 2.10.0 final from the RC2

Tim Sheppard added some commits
Tim Sheppard Extracted versions into new object and created new val for the cross …
…versions
08980a7
Tim Sheppard Added creation of options list
The inputs args are now parsed for tags, options and names.

Tags begin with `@` or `~@`
Options either begin with `--` or match `-[a-z]`
Names are all those args that are neither a Tag or an Option

The new Options list is now appended to the runner args.
046c5b1
Tim Sheppard Changed implementation of option checking to use a fixed whitelist of…
… supported options rather than pattern match.

This makes it much more robust and will not pass parameters that are not supported or handled by the plugin in a different way.
82647b6
@skipoleschris

Thanks for the patch. I used this as a basis for a fix as follows:

  • There is a new task cucumber-dry-run that runs cucumber with the --dry-run flag enabled
  • There is a new boolean setting cucumberStrict to enable or disable strict mode
  • There is a new boolean setting cucumberMonochrome to enable or disable monochrome mode

I think this fits better with the general approach of hiding the details of cucumber behind sbt settings. Hope that's oaky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2013
  1. Extracted versions into new object and created new val for the cross …

    Tim Sheppard authored
    …versions
  2. Added creation of options list

    Tim Sheppard authored
    The inputs args are now parsed for tags, options and names.
    
    Tags begin with `@` or `~@`
    Options either begin with `--` or match `-[a-z]`
    Names are all those args that are neither a Tag or an Option
    
    The new Options list is now appended to the runner args.
  3. Changed implementation of option checking to use a fixed whitelist of…

    Tim Sheppard authored
    … supported options rather than pattern match.
    
    This makes it much more robust and will not pass parameters that are not supported or handled by the plugin in a different way.
This page is out of date. Refresh to see the latest.
View
34 plugin/src/main/scala/templemore/sbt/cucumber/Integration.scala
@@ -9,6 +9,7 @@ import templemore.sbt.util._
* cucumber as both a forked JVM and within the current JVM process.
*
* @author Chris Turner
+ * @author RandomCoder
*/
trait Integration {
@@ -32,20 +33,41 @@ trait Integration {
}
}
+ /*
+ * The options that are supported by the plugin.
+ * This excludes options that are set in other places such as formatting
+ * and dotcucumber etc.
+ *
+ * This is essentially a list of the parameter-less options supported by the
+ * `cucumber-jvm` `cucumber.runtime.RuntimeOptions` class
+ *
+ * The `--no-xxx` version of the options are not included as they are not enabled
+ * by default and are therefore not really necessary.
+ */
+ private val supportedOptions = Seq("-d",
+ "--dry-run",
+ "-s",
+ "--strict",
+ "-m",
+ "--monochrome")
+
+
private def runCucumber(args: Seq[String],
jvmSettings: JvmSettings,
options: Options,
output: Output,
log: Logger) = {
def tagsFromArgs = args.filter(isATag).toList
- def namesFromArgs = args.filter(isNotATag).toList
+ def optsFromArgs = args.filter(isAnOption).toList
+ def namesFromArgs = args.filter(isAName).toList
- def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~")
- def isNotATag(arg: String) = !isATag(arg)
+ def isAnOption(arg: String) = supportedOptions.contains(arg)
+ def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~@")
+ def isAName(arg:String) = !isATag(arg) && !isAnOption(arg)
log.info("Running cucumber...")
options.beforeFunc()
- val result = launchCucumberInSeparateJvm(jvmSettings, options, output, tagsFromArgs, namesFromArgs)
+ val result = launchCucumberInSeparateJvm(jvmSettings, options, output, tagsFromArgs, namesFromArgs, optsFromArgs)
options.afterFunc()
result
}
@@ -54,7 +76,8 @@ trait Integration {
options: Options,
output: Output,
tags: List[String],
- names: List[String]): Int = {
+ names: List[String],
+ cucumberOptions: List[String]): Int = {
def makeOptionsList(options: List[String], flag: String) = options flatMap(List(flag, _))
val cucumberParams = ("--glue" :: options.basePackage :: Nil) ++
@@ -62,6 +85,7 @@ trait Integration {
output.options ++
makeOptionsList(tags, "--tags") ++
makeOptionsList(names, "--name") ++
+ cucumberOptions ++
(options.featuresLocation :: Nil)
JvmLauncher(jvmSettings).launch(cucumberParams)
}
View
20 project/Build.scala
@@ -1,9 +1,11 @@
import sbt._
import Keys._
+import Versions._
+
object Settings {
val buildOrganization = "templemore"
- val buildScalaVersion = "2.9.2"
+ val buildScalaVersion = scala2_9
val buildVersion = "0.7.2"
val buildSettings = Defaults.defaultSettings ++
@@ -16,9 +18,6 @@ object Settings {
object Dependencies {
- private val CucumberVersionForScala2_9 = "1.0.9"
- private val CucumberVersionForScala2_10 = "1.1.1"
-
def cucumberScala(scalaVersion: String) = {
def cucumberVersion = if ( scalaVersion.startsWith("2.10") ) CucumberVersionForScala2_10 else CucumberVersionForScala2_9
"info.cukes" % "cucumber-scala" % cucumberVersion % "compile"
@@ -32,9 +31,11 @@ object Build extends Build {
import Dependencies._
import Settings._
+ private val crossVersions = Seq(scala2_9, scala2_10)
+
lazy val parentProject = Project("sbt-cucumber-parent", file ("."),
settings = buildSettings ++
- Seq(crossScalaVersions := Seq("2.9.2", "2.10.0-RC2"))) aggregate (pluginProject, integrationProject)
+ Seq(crossScalaVersions := crossVersions)) aggregate (pluginProject, integrationProject)
lazy val pluginProject = Project("sbt-cucumber-plugin", file ("plugin"),
settings = buildSettings ++
@@ -42,8 +43,15 @@ object Build extends Build {
lazy val integrationProject = Project ("sbt-cucumber-integration", file ("integration"),
settings = buildSettings ++
- Seq(crossScalaVersions := Seq("2.9.2", "2.10.0-RC2"),
+ Seq(crossScalaVersions := crossVersions,
libraryDependencies <+= scalaVersion { sv => cucumberScala(sv) },
libraryDependencies += testInterface))
}
+
+object Versions {
+ val scala2_9 = "2.9.2"
+ val scala2_10 = "2.10.0"
+ val CucumberVersionForScala2_9 = "1.0.9"
+ val CucumberVersionForScala2_10 = "1.1.1"
+}
Something went wrong with that request. Please try again.