File-Based
File-Based
Both sibling and nested structures are fully supported with the rempts' multi-level file-based subcommand logic!
Let's break down what is possible and how the CLI will resolve each case:
1. Structure: Sibling subcommands
app/
foo/
cmd.ts
bar/
cmd.ts
baz/
cmd.tsSupported invocations:
my-cli foo
→ Loadsapp/foo/cmd.tsmy-cli foo bar
→ Loadsapp/foo/bar/cmd.tsmy-cli foo baz
→ Loadsapp/foo/baz/cmd.ts
How it works:
The loader checks for a subfolder matching the next argument. If it exists, it recurses into it. If not, it loads cmd.ts in the current directory.
2. Structure: Nested subcommands
app/
foo/
cmd.ts
bar/
baz/
cmd.tsSupported invocations:
my-cli foo
→ Loadsapp/foo/cmd.tsmy-cli foo bar baz
→ Loadsapp/foo/bar/baz/cmd.ts
How it works:
- For
foo bar baz, it goes:
app/foo→app/foo/bar→app/foo/bar/baz→ loadscmd.tsin the deepest directory.
3. Structure: Only nested, no sibling
app/
foo/
bar/
baz/
cmd.tsSupported invocations:
my-cli foo bar baz
→ Loadsapp/foo/bar/baz/cmd.ts
4. Structure: Only top-level
app/
foo/
cmd.tsSupported invocations:
my-cli foo
→ Loadsapp/foo/cmd.ts
Summary
- You can have both
cmd.tsin a directory and subfolders with their owncmd.ts. - The loader always prefers to recurse into a subfolder if the next argument matches a directory.
- If no matching subfolder is found, it loads
cmd.tsin the current directory. - This allows for both sibling and nested subcommands, and for a directory to act as both a command and a parent for further subcommands.
You can mix and match these patterns freely!