casey / just

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

Cannot retrieve [doc] attribute content and comment of a module at the same time with json dump #2463

Open Retorikal opened 1 day ago

Retorikal commented 1 day ago

Given the following justfile and any random but validly formatted somemodule.justfile:

# Module comment
[doc('Module doc')]
mod somemodule

# Recipe comment
[doc('Recipe doc')]
somerecipe:
    echo "Recipe echo"
    read -p "Press any key to continue..." -n 1 -r

when running just --dump --dump-format=json, results in the following (parts omitted for brevity, full at pastebin):

{
    "modules": {
        "somemodule": {
            "doc": "Module doc",
            ...
        }
    },
    "recipes": {
        "somerecipe": {
            "attributes": [
                {
                    "doc": "Recipe doc"
                }
            ],
            "doc": "Recipe comment",
            ...
        }
    },
    ...
}

On the recipe, content of doc attribute and comment is put on different fields. But on module, content of doc attribute overwrites doc field, so "Module comment" does now show up anywhere on the output.

(Edit: The justfile snippet used to generate the output was outdated when this issue was initially made)

casey commented 1 day ago

interesting issue! It doesn't seem ideal that recipe.doc is different from the contents of the doc attribute, since the doc attribute effectively replaces the doc comment in --list. Is there a use case for having access to both?

Retorikal commented 1 day ago

I'm making a front-end for a set of justfiles that I have, and needed to add a user-friendly name and description for each module and recipe included in it. I'm thinking of adding the user-friendly name on the doc attribute, and the description on the doc comment.

Aside from the usecase, it does seem weird that on a module doc attribute overwrites doc comment, but on recipe it does not.

adienakhmad commented 1 day ago

I'm not sure if this is directly related but it seems like just --fmt is correctly preserving comment on recipes but removing them on module.

just --fmt --unstable --check

-# setup a CAN network
 mod cansetup
-# adjust or tune a CAN network
 mod cantweak
-# benchmark, stress test a CAN network
 mod canbench
-# monitor a CAN network
 mod canmonitor

 ..
 <trimmed>
 ..

 error: Formatted justfile differs from original.