views:

95

answers:

2

I'm trying to write a script to make generating Lift projects quicker but I believe i'm running into a white space issue.

val strLiftGen = "mvn archetype:generate -U\-DarchetypeGroupId=net.liftweb\
 -DarchetypeArtifactId=lift-archetype-blank\
 -DarchetypeVersion=1.0\
 -DremoteRepositories=http://scala-tools.org/repo-releases\-DgroupId=" + args(0)"\-DartifactId=" + args(1)"\-Dversion=1.0-SNAPSHOT */"

Anyone care to hit the newb with the stick of wisdom and tell me a smart way of handling a long string like this?

+2  A: 

If you're trying to get a string with some occurrences of a backslash-escaped space, then you need to double up the backslash. As it stands, what you've shown will not actually compile because a single backslash may not immediately precede a space.

You may want to use a triple-quoted string, which suspends all backslash processing and allows embedded newlines. Backslashes never need to be doubled in triple-quoted strings.

Randall Schulz
+4  A: 

There are multiple syntax errors in your example ("\ " and missing + after args(0) and args(1). (copy paste error?). Here is what you can do:

val strLiftGen =
  """mvn
  archetype:generate
  -U
  -DarchetypeGroupId=net.liftweb
  -DarchetypeArtifactId=lift-archetype-blank
  -DarchetypeVersion=1.0
  -DremoteRepositories=http://scala-tools.org/repo-releases
  -DgroupId=%s
  -DartifactId=%s
  -Dversion=1.0-SNAPSHOT"""

val cleanStr = strLiftGen.replace('\n',' ').replaceAll("\\s{2,}"," ").trim
println(cleanStr.format(args(0), args(1)))

Then how you handle whitespace between arguments depends a bit on how you'll execute the command.

huynhjl
cool, much cleaner as well! never would have thought of that!hrmm as for execution i'm at LiftGenerate com.test test so groupID and then artifactId.
Uruhara747