Add support for multi-file CLI command scripts embedded into the lute executable#314
Merged
Add support for multi-file CLI command scripts embedded into the lute executable#314
Conversation
aatxe
reviewed
Jun 3, 2025
aatxe
approved these changes
Jun 4, 2025
vrn-sn
commented
Jun 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In this PR, we add support for running command-line Luau scripts that are stored in the
cli/commandsdirectory.If we have
cli/commands/foo.luauorcli/commands/foo/init.luau, runninglute foowill automatically execute the contents of that script (with support for relative requires as well).Implementation details
We create a new
CliVfsthat can optionally be embedded inRequireVfs. The CLI enables this, butvm.createdoes not, as it does not need a custom VFS for command-line scripts. The actual implementation of the VFS is nearly identical toStdLibVfs.The embedding of the CLI scripts is done using Luthier to generate source files for a new
Lute.CLI.Commandstarget. This is similar to how the@stdlibraries were embedded into theLute.Stdtarget.std/libslibraries to track stale generated files #205While working on this, I noticed that
luthier.luauwas incomplete. Due to the lack of anos.walkAPI like we have in Python,luthier.luaudoesn't correctly handle nested directories that need to be embedded. To solve this, I have added atraverseFileTreefunction that effectively accomplishes the same thing.Because of slight differences in the order files are processed by
os.walkandtraverseFileTree,luthier.pyandluthier.luauspit out different hashes. I think this is fine. When only using one of the tools in isolation, the caching seems to work as expected.