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

[Request] Support Command Groups #1591

Closed
SpaceshipOperations opened this issue May 1, 2023 · 1 comment
Closed

[Request] Support Command Groups #1591

SpaceshipOperations opened this issue May 1, 2023 · 1 comment

Comments

@SpaceshipOperations
Copy link

SpaceshipOperations commented May 1, 2023

(First of all, thank you for creating this wonderful command runner. After spending a long time debating between the various alternates to Makefile, writing my own shell scripts, or what, I discovered just a brief while ago, and it immediately became my favorite.)

As the title says, I would like to be able to organize recipes into groups, similar to GitHub's gh command. Example usage:

# user group
just user list
just user show NAME
just user create NAME
just user delete NAME

# product group
just product list
just product show NAME
just product create NAME
just product delete NAME

# etc.

As for how the syntax or mechanism for achieving this inside justfiles might look like, there could be multiple ways for doing so, and I suppose deciding which one is best might need some discussion among the developers and community, but I'm going to both humor you and give you a serious suggestion by telling you the following story.

I asked ChatGPT: "I want to write a just file where commands are divided into groups, where each group contains sub-commands. Is there a particular way that is considered idiomatic for doing so in just files?"

In its sheer magnificence, ChatGPT hallucinated the following answer:

Yes, there is a common way to organize commands into groups with sub-commands in a Justfile. Here's an example of how you can achieve this:

# Define a group of tasks with a common prefix
# Example: just build.app
# Example: just build.library
build:
    # The build group has its own set of sub-tasks
    # Example: just build.app.android
    app.android:
        echo "Building Android app"

    app.ios:
        echo "Building iOS app"

    library:
        echo "Building library"

Initially wondering whether a feature like this actually exists and I simply missed it, I pasted it into a justfile and invoked it, only to get some syntax errors...

That said, I think ChatGPT's entertaining hallucination seriously seems like a nice idea, as it would make writing justfiles with command groups very simple, natural and easy as a breeze, at least from the perspective of the user.

However, from the perspective of Just's developers, it might be troublesome, as determining that whether something is a recipe or a group relies on matching the first line of the indented block against recipe definition syntax and then checking if the subsequent line is indented, and unfortunately this is error-prone and can result in confusing errors for the user.

Fortunately, the ambiguity can be alleviated by requiring that groups headings are marked in some unambiguous way. For example:

[group]
build:
    android:
        echo "Building Android app"

    ios:
        echo "Building iOS app"

Also note that ChatGPT's suggestion involves using a period between the group name and the command name in the command-line. While personally I prefer not to have it that way from a pure stylistic perspective, but from an implementation perspective, it might simplify things a great deal for both Just's developers and even the users, as you no longer have to wonder if a command-line like just build android means "Invoke the two recipes build and android" or "Invoke the android recipe from the build group".

I have another suggestion that might make implementing groups even simpler, which is allowing periods in recipe names and making it so that the shell completion only lists commands in the current nesting level. For example, if we have recipes called build.android, build.ios, test.android, test.ios, then typing just and pressing tab would just list only build. and test., but if the command-line is just build., then the completion function would list build.android and build.ios, and this would work with an arbitrary number of nesting levels.

If done like this, it would be much easier to implement, and as a bonus, it would allow offering an extra feature, which is that unless a recipe called build is explicitly defined, then invoking just build would automatically invoke all recipes with the build. prefix.

As you can see, there are various ways to do this, and deciding which one is best might need some discussion, but in any case personally I think it would be pretty nice to have in one form or another.

Thank you in advance.

@casey
Copy link
Owner

casey commented May 1, 2023

Check out #383, which I think tracks what you're interested in.

@casey casey closed this as completed May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants