Repository: casey/just (rust)

Issue:
Fallback for submodules
@casey Thanks for adding submodule support, it's working great.

Currently, when you invoke a submodule recipe within a directory containing a justfile with `set fallback` but no submodules defined (the requested submodule is defined in a parent justfile), the following error is encountered:

```pwsh
❯ just myapp::start       
error: Justfile does not contain submodule `myapp`
```

It would be nice if the `fallback` setting (or another one, e.g. `fallback-submodules`) would allow `just` to look for a requested submodule in parent justfiles.

Sometimes you are in a nested folder structure, and you quickly want to call a recipe defined in the root justfile. Since fallback does not work for submodules, the workaround is to add the submodule to the justfile at your level in the hierarchy (even though the recipe you want to run is unrelated to that justfile), or to cd back to the root and run the recipe from there, or to add a recipe in the root justfile that calls into its own submodule definition.

### Example

This is what happens currently:

```pwsh
❯ cd proj/foo/bar
❯ just --version    
just 1.34.0
❯ just hello
hello
❯ just myapp::start       
error: Justfile does not contain submodule `myapp`
```

This is what should happen:

```pwsh
❯ cd proj/foo/bar
❯ just hello
hello
❯ just myapp::start       
starting
```

#### proj/justfile

```justfile
mod myapp 'justfile-myapp.just'
default:
  just --list
```

#### proj/justfile-myapp.just

```justfile
start:
  @echo "starting"
```

#### proj/foo/bar/justfile

```justfile
set fallback
# set fallback-submodules

hello:
  @echo "hello"
```


Pull request:
Make fallback work with recipes in submodules
Fixes #2327

Patch:
diff --git a/src/subcommand.rs b/src/subcommand.rs
index fa6f1e0b..cbb53d89 100644
--- a/src/subcommand.rs
+++ b/src/subcommand.rs
@@ -147,7 +147,7 @@ impl Subcommand {
         };
 
         match Self::run_inner(config, loader, arguments, overrides, &search) {
-          Err((err @ Error::UnknownRecipe { .. }, true)) => {
+          Err((err @ (Error::UnknownRecipe { .. } | Error::UnknownSubmodule { .. }), true)) => {
             match search.justfile.parent().unwrap().parent() {
               Some(parent) => {
                 unknown_recipes_errors.get_or_insert(err);


Test patch:
diff --git a/tests/fallback.rs b/tests/fallback.rs
index 3330e17a..238a12a7 100644
--- a/tests/fallback.rs
+++ b/tests/fallback.rs
@@ -362,3 +362,15 @@ fn stop_fallback_when_fallback_is_false() {
     .status(EXIT_FAILURE)
     .run();
 }
+
+#[test]
+fn works_with_modules() {
+  Test::new()
+    .write("bar/justfile", "set fallback := true")
+    .write("foo.just", "baz:\n @echo BAZ")
+    .justfile("mod foo")
+    .args(["foo::baz"])
+    .current_dir("bar")
+    .stdout("BAZ\n")
+    .run();
+}