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

update suggested default recipe to include a justfile option #1296

Merged
merged 6 commits into from
Aug 1, 2022

Conversation

jpbochi
Copy link
Contributor

@jpbochi jpbochi commented Jul 28, 2022

This is an update to documentation, with a better recipe suggestion.


I had a justfile with the following content:

# as suggested at [Listing Available Recipes](https://just.systems/man/en/chapter_22.html)
default:
  @just --list

pwd:
  pwd

Then, I tried to run .j (aliased to just -f ~/.justfile -d . as suggested at User justfiles), and got the following error:

$ .j
error: No justfile found
error: Recipe `default` failed on line 4 with exit code 1

Running .j pwd worked. The issue if that .j would run the default recipe, which executes just --list without passing the --justfile option again.

@casey
Copy link
Owner

casey commented Jul 28, 2022

Good idea!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
```

Note that the `--justfile {{justfile()}}` above is needed to make sure the listed recipes are from the current `justfile`. Without it, if you executed `just -f /some/distant/justfile` or `just -f ./non-standard-justfile`, the plain `just --list` call in the `default` recipe would not use the file you provided. It would try to find a justfile in your current path, maybe even resulting in a `No justfile found` error.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casey Is this better?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is just -f /some/distant/justfile a problem? I think just will switch its working directory and find the justfile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case of that .j alias, the directory is already set. I don't think there's other solution to combine both (the alias and the list recipe, I mean).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more generic feature that just may need is an alternative to this $(MAKE) $(MFLAGS) for calling a "sub" just.

Maybe, a just() function could be equivalent to {{just_executable()}} --justfile {{justfile()}}. Then, recommend that any recursive just calls are made with {{just()}} instead of plainly just.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need something like. I want some way of running a just command in the middle of a recipe, but we haven't figured out the syntax yet.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble reproducing the behavior you mentioned. I created a justfile in foo/.justfile, which has just --list in the first recipe, calling just -f foo/.justfile seems to work, it successfully calls just and lists the recipes in the justfile.

Copy link
Contributor Author

@jpbochi jpbochi Jul 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output below may help.

Notice that:

  1. the jj alias includes a -d . option, as is suggested at https://just.systems/man/en/chapter_63.html#forwarding-alias;
  2. all executions of jj did echo just --list, meaning it's running the recipe from ~/justfile
  3. when pwd is inside my home (e.g. ~/src/), jj works as intended.
  4. when pwd is outside of ~, I get a No justfile found coming from the default recipe;
  5. when pwd is in a directory with another justfile, it lists recipes from that directory instead.

The only way I see to prevent the unintended behavior (4 and 5) is by changing the recipe to say just --justfile {{justfile()}} --list.

$ cat ~/justfile
default:
  just --list

pwd:
  pwd

$ type jj
jj is aliased to `just -f ~/justfile -d .'

$ cd ~/src
$ jj
just --list
Available recipes:
    default
    pwd

$ cd /
$ jj
just --list
error: No justfile found
error: Recipe `default` failed on line 2 with exit code 1

$ cd ~/src/jp/just/
$ jj
just --list
Available recipes:
    build
    build-book
    changes                   # add git log messages to changelog
    check
    c                         # alias for `check`
    …

@casey
Copy link
Owner

casey commented Jul 30, 2022

Ah, okay, sorry, I misunderstood. I thought that it was just the -f flag that would make things not work, but it's the -d flag. I'm actually leaning towards not changing the recipe, and just adding the note, mentioning that if you have a non-default justfile name or different directory, you'll need to to add --justfile {{justfile()}}.

@jpbochi
Copy link
Contributor Author

jpbochi commented Aug 1, 2022

@casey I'm cool with that, too. The current example would work as is for the majority of cases, and there's value in keeping them simple.

I updated the code with that now.

README.md Outdated Show resolved Hide resolved
@casey casey enabled auto-merge (squash) August 1, 2022 14:30
@casey casey merged commit 051f438 into casey:master Aug 1, 2022
@casey
Copy link
Owner

casey commented Aug 1, 2022

Nice! I added the -d flag to the first example, since that's needed to get it to break.

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

Successfully merging this pull request may close these issues.

2 participants