Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base output directory should strip non-word characters #274

Open
TimMoore opened this issue Mar 20, 2017 · 9 comments
Open

Base output directory should strip non-word characters #274

TimMoore opened this issue Mar 20, 2017 · 9 comments

Comments

@TimMoore
Copy link

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.

@eed3si9n
Copy link
Member

ok, but who puts commas in the project name?

@TimMoore
Copy link
Author

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
Copy link
Author

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

@eed3si9n
Copy link
Member

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

Sure. Why not.

@foxmk
Copy link
Contributor

foxmk commented Apr 1, 2017

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

@TimMoore
Copy link
Author

TimMoore commented Apr 3, 2017

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

@foxmk foxmk self-assigned this Apr 3, 2017
@foxmk foxmk removed their assignment Jun 30, 2017
@TonioGela
Copy link
Member

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?

@eed3si9n
Copy link
Member

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

@TonioGela
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants