Skip to content

Add support for multi-file CLI command scripts embedded into the lute executable#314

Merged
aatxe merged 6 commits intoprimaryfrom
vrn-sn/run-cli-commands
Jun 4, 2025
Merged

Add support for multi-file CLI command scripts embedded into the lute executable#314
aatxe merged 6 commits intoprimaryfrom
vrn-sn/run-cli-commands

Conversation

@vrn-sn
Copy link
Copy Markdown
Member

@vrn-sn vrn-sn commented Jun 3, 2025

Summary

In this PR, we add support for running command-line Luau scripts that are stored in the cli/commands directory.

If we have cli/commands/foo.luau or cli/commands/foo/init.luau, running lute foo will automatically execute the contents of that script (with support for relative requires as well).

Implementation details

We create a new CliVfs that can optionally be embedded in RequireVfs. The CLI enables this, but vm.create does not, as it does not need a custom VFS for command-line scripts. The actual implementation of the VFS is nearly identical to StdLibVfs.

The embedding of the CLI scripts is done using Luthier to generate source files for a new Lute.CLI.Commands target. This is similar to how the @std libraries were embedded into the Lute.Std target.

While working on this, I noticed that luthier.luau was incomplete. Due to the lack of an os.walk API like we have in Python, luthier.luau doesn't correctly handle nested directories that need to be embedded. To solve this, I have added a traverseFileTree function that effectively accomplishes the same thing.

Because of slight differences in the order files are processed by os.walk and traverseFileTree, luthier.py and luthier.luau spit out different hashes. I think this is fine. When only using one of the tools in isolation, the caching seems to work as expected.

@vrn-sn vrn-sn marked this pull request as ready for review June 3, 2025 21:38
@aatxe aatxe merged commit dfbd9f8 into primary Jun 4, 2025
7 checks passed
@aatxe aatxe deleted the vrn-sn/run-cli-commands branch June 4, 2025 00:01
@vrn-sn vrn-sn mentioned this pull request Feb 10, 2026
aatxe pushed a commit that referenced this pull request Feb 10, 2026
This was added back in the early days of Lute, when I first implemented
the `CliVfs` and we had no other examples of embedded CLI commands:
#314.

We have no need for `lute helloworld` anymore and can clean this up.
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