casey / just

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

Submodules should be groupable (or have their own group) #2243

Closed FelixZY closed 1 month ago

FelixZY commented 1 month ago

I've started grouping commands because that makes them easier to find and read. I'm also using submodules to group certain commands specific to e.g. database commands. However, when listing these using

# Show this help text
[group("General")]
help:
    @just --list --unsorted --justfile {{ justfile() }}

the submodules are simply appended to the grouped output, making it appear as if they are part of the last declared group:

Available recipes:
    [General]
    help                # Show this help text

    [Code Utils]
    format              # Reformat all source files
    lint                # Lint source files

    [Environment]
    chenv new_env       # CHange ENVironment
    genenv              # Generate a .env file based on secrets/{environment}. Set the `ENVIRONMENT` envvar to change environment.
    current_environment # Print the environment of the variables in the current .env file
    app ...             # Application commands
    auth ...            # Authentication module commands
    db ...              # Database management commands

At a minimum, I would expect the submodules to be grouped separately:

    [Environment]
    chenv new_env       # CHange ENVironment
    genenv              # Generate a .env file based on secrets/{environment}. Set the `ENVIRONMENT` envvar to change environment.
    current_environment # Print the environment of the variables in the current .env file

    app ...             # Application commands
    auth ...            # Authentication module commands
    db ...              # Database management commands

At best, I would like to be able to set custom groups for my submodules:

# Application commands
[group("General")]
mod app "src/app/.app.justfile"

# Authentication module commands
[group("Subcommands")]
mod auth "src/auth/.auth.justfile"

# Database management commands
[group("Subcommands")]
mod db "src/db/.db.justfile"
Available recipes:
    [General]
    help                # Show this help text
    app ...             # Application commands

    [Subcommands]
    auth ...            # Authentication module commands
    db ...              # Database management commands

    [Code Utils]
    format              # Reformat all source files
    lint                # Lint source files

    [Environment]
    chenv new_env       # CHange ENVironment
    genenv              # Generate a .env file based on secrets/{environment}. Set the `ENVIRONMENT` envvar to change environment.
    current_environment # Print the environment of the variables in the current .env file
casey commented 1 month ago

Thanks for trying out modules!

I think these would be good changes. I added a space before submodules in --list when groups are present in #2244.

Putting modules into groups is a larger change, since it involves modifying the parser to accept attributes on modules, but it seems like a good idea, if anyone wants to tackle it.

FelixZY commented 1 month ago

Awesome, thanks - as always - for the quick fix @casey !

neunenak commented 1 month ago

I'm working on a PR https://github.com/casey/just/pull/2247 that allows the doc attribute on modules; that has the parser changes necessary to make adding the group attribute on modules possible as well.

jmwoliver commented 1 month ago

I have a potential fix for this in this PR: https://github.com/casey/just/pull/2263. Feel free to review whenever you get the chance!

jmwoliver commented 1 month ago

@casey Is there any documentation I can update in the README for #2263? I was looking at updating the Recipe Groups and Modules sections with examples for grouping modules, but wasn't sure if that was the way to go. Let me know what you prefer and I'm happy to update the docs.

casey commented 1 month ago

I just merged #2282, which adds some initial documentation to the attributes section, regarding which attributes apply to which types of items. Feel free to open another PR if you think further documentation would be helpful!