giter8
giter8 copied to clipboard
Base output directory should strip non-word characters
For example:
$ sbt new file:///Users/tmoore/Projects/lagom/lagom-java.g8
[info] Loading global plugins from /Users/tmoore/.sbt/0.13/plugins
[info] Set current project to java (in build file:/Users/tmoore/Projects/tmp/java/)
name [Hello]: Hello, world!
organization [com.example]:
version [1.0-SNAPSHOT]:
lagom_version [1.3.1]:
Template applied in ./hello,-world!
I would have expected it to name the directory "hello-world" without the additional punctuation.
This could be fixed one of two ways:
- Apply the "word-only" format to the "name" parameter when constructing the base directory.
- Apply the "word-only" format to the "normalize" format itself before hyphenating.
I think that the second option makes sense for an intuitive understanding of what "normalize" ought to do, but it might be an unexpected change for some people.
I'm interested in people's thoughts, and I can make a pull request with whatever the consensus is.
ok, but who puts commas in the project name?
I just did 😛
The tool doesn't give any indication of how the name is used. Is it just the directory name, or is it a human-readable name for the project?
It doesn't tell you not to use punctuation, or warn you if you do, it just generates broken projects. This isn't great from a user experience perspective.
@eed3si9n if I work on a pull request that includes word-only in normalize, would you be willing to accept it?
if I work on a pull request that includes word-only in normalize, would you be willing to accept it?
Sure. Why not.
@TimMoore Is this fix still in progress? If not, I can take it.
@foxmk I haven't had a chance to start on it yet... please go ahead! 😄
The fix is as simple as changing this line from
parameters.get("name").map(workingDirectory / G8.normalize(_))
to something like:
parameters.get("name").map(name => workingDirectory / G8.normalize(name.replaceAll("""\W""", " ").trim()))
Using wordOnly will remove any space in the string, making the hyphenate part of thenormalize step totally useless, so a raw replaceAll like replaceAll("""\W""", " ") has to be preferred.
A thing to note btw is that \W includes commonly used symbols like _ and -, so the net effect is that a name like hello_world will be transformed to hello-world.
It's not difficult. It's just a matter of deciding which transformation to use. In any case, this will be a breaking change that will affect the next version, so maybe it's better to do not "act" at all.
@eed3si9n, @xuwei-k, do you have any thoughts about it?
I guess we could do something like name.replaceAll("""[^a-zA-Z0-9\-_]""", " ") so _ and - are accepted?
I guess we could do something like
name.replaceAll("""[^a-zA-Z0-9\-_]""", " ")so_and-are accepted?
It's a good idea. Maybe it's worth extracting it in an ad-hoc templatizing function? And what about non-retrocompatibility?