casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
21.5k stars 476 forks source link

Allow numbers at start of recipe names #1271

Open samatjain opened 2 years ago

samatjain commented 2 years ago

I like that https://github.com/secretGeek/ok-bash lets you run recipes by number, i.e. ok 1 to run the first command in an okfile.

Hypothetically, the equivalent in just would be giving a recipe name of "1" so you could just run just 1, but that does not work. Using justfile:

1:
  echo "Hello world"

and executing it with just:

error: Unknown start of token:
  |
4 | 1:
  |

Similarly, if you want to keep just --list ordered (which sorts recipes by default), you might want to prefix recipes with, "01-", "02-", but that also fails the same as above; recipe names cannot begin with numbers.

Also, aliases should support this as well. Fails similarly:

error: Unknown start of token:
  |
4 | alias 1 := default
  |
casey commented 2 years ago

I've sort of avoided this so far because I wanted to follow the normie programming language rule of making identifiers and numbers lexically distinct, so they that the grammar, if it ever includes numbers, can disambiguate them.

just --list --unsorted (I know, super unwieldy) allows listing recipes in the order they appear in the justfile. One option to make this eaiser would be to add a setting to show them in definition order, like set list-unsorted :: true.

just 1 could be made to work, since the argument parser and the recipe parser are separate, although it seems suuuuuper illegible. Would a one-letter alias, e.g. just a be as good? Also don't have to reach to the numbers when typing.

samatjain commented 2 years ago

I've sort of avoided this so far because I wanted to follow the normie programming language rule of making identifiers and numbers lexically distinct, so they that the grammar, if it ever includes numbers, can disambiguate them.

I feel that is a C-ish thing and other languages with units support, e.g. for C you can't disambiguate "1U" from a literal "unsigned 1" or identifier "1U". Will just ever have to deal with this stuff? I don't think so…

Would a one-letter alias, e.g. just a be as good? Also don't have to reach to the numbers when typing.

Funny you mention, I had been using 'a', 'b', etc as a workaround for not supporting numbers as recipe names, but for me personally I've found these are harder to type than the ergonomics of '1', '2' as I had been doing with 'ok'. Now I know about --unsorted, I'm going to try the ergonomics of using 'q', 'w', 'e'. However, I still think I prefer numbers, and others may do so as well.

casey commented 2 years ago

Will just ever have to deal with this stuff? I don't think so…

I think you're probably right, but I jealously guard syntactic space, since it provides a lot of flexibility for the future. Since numbers are currently a compilation error, they can be used to introduce a new feature in a backwards-compatible way.

I'd be fine with changing the argument parser to accept numbers in recipe-name positions, since that wouldn't actually change what tokens are accepted in justfiles.

runeimp commented 2 years ago

One possibility if you do add this support would be to have the output of --list --unsorted or if set list-unsorted :: true to do a numbered list like

Available recipes:
   1. list-recipes # default to list all the recipes
   2. build        # Build the code
   3. clean        # Clean the build environment
 ...
  10. term-wipe    # Clear the terminal buffer

So the actual reference numbers to be used are easily trackable. Especially when recipes are added or moved around.

casey commented 2 years ago

@runeimp Good idea! I like that.

samatjain commented 2 years ago

@runeimp I like that idea. Would invoking a numbered item e.g. just 1 invoke the corresponding numbered recipe as given by just --list --unsorted?

This way, no grammar adjustment is needed for justfiles, and allowing numbers at the start of recipe names won't be needed.