giter8 icon indicating copy to clipboard operation
giter8 copied to clipboard

Base output directory should strip non-word characters

Open TimMoore opened this issue 8 years ago • 9 comments

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:

  1. Apply the "word-only" format to the "name" parameter when constructing the base directory.
  2. 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.

TimMoore avatar Mar 20 '17 02:03 TimMoore

ok, but who puts commas in the project name?

eed3si9n avatar Mar 20 '17 02:03 eed3si9n

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.

TimMoore avatar Mar 20 '17 02:03 TimMoore

@eed3si9n if I work on a pull request that includes word-only in normalize, would you be willing to accept it?

TimMoore avatar Mar 20 '17 02:03 TimMoore

if I work on a pull request that includes word-only in normalize, would you be willing to accept it?

Sure. Why not.

eed3si9n avatar Mar 20 '17 02:03 eed3si9n

@TimMoore Is this fix still in progress? If not, I can take it.

foxmk avatar Apr 01 '17 22:04 foxmk

@foxmk I haven't had a chance to start on it yet... please go ahead! 😄

TimMoore avatar Apr 03 '17 01:04 TimMoore

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?

TonioGela avatar May 30 '21 16:05 TonioGela

I guess we could do something like name.replaceAll("""[^a-zA-Z0-9\-_]""", " ") so _ and - are accepted?

eed3si9n avatar May 31 '21 01:05 eed3si9n

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?

TonioGela avatar May 31 '21 07:05 TonioGela