reibitto / sbt-welcome

An SBT plugin for displaying a welcome message and commonly used tasks.
Apache License 2.0
79 stars 4 forks source link

Support numbers list for auto aliases #11

Closed geirolz closed 1 month ago

geirolz commented 1 month ago

It would be nice to have a key to specify the auto alias strategy, having the possibility to choose between letters and numbers.

Example with Letters

// With or without  since Letters is the Default
aliasStrategy := AliasStrategy.AutoWithLetters 

Produces:

[info] Useful sbt tasks:
[info] a. run - Start application
[info] b. test - Run unit tests
[info] c. it:test - Run integration unit tests

Example with Numbers

aliasStrategy := AliasStrategy.AutoWithNumbers

Produces:

[info] Useful sbt tasks:
[info] 1. run - Start application
[info] 2. test - Run unit tests
[info] 3. it:test - Run integration unit tests
reibitto commented 1 month ago

I actually wanted to use numbers as the default from the start but sbt doesn't allow aliases to start with a number. I guess it's similar rules to scala identifiers (can have a number in it but can't start with one).

I tried it again just in case and get this from sbt (using plain addCommandAlias):

Invalid alias name '1'.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)
geirolz commented 1 month ago

Ouch! I see

What if we add a letter as prefix of the numbers ? Like t for Task

[info] Useful sbt tasks:
[info] t1. run - Start application
[info] t2. test - Run unit tests
[info] t3. it:test - Run integration unit tests

It's a tread off, I know

I don't see many other solutions give this limitation unfortunately. It would be interesting asking to SBT why they don't support number aliases

reibitto commented 1 month ago

That seems reasonable. By the way, you can already do this currently but I noticed that I hadn't documented it in the README. The following should do what you want:

autoAliasGen := LazyList.from(1).map(n => s"t$n")

(note that sbt uses Scala 2.12 so the LazyList here is at scala.collection.compat.immutable.LazyList)

Anyway I'll document that now. In future versions I could perhaps add some built-in commonly used generators. But maybe it's not worth it either considering it's a simple one-liner most of the time.

geirolz commented 1 month ago

Thank you so much @reibitto!