@@ -39,8 +39,8 @@ static const char* HELP_STRING = R"(Usage: lute <command> [options] [arguments..
3939 check Type check Luau files.
4040 compile Compile a Luau script into a standalone executable.
4141 setup Generate type definition files for the language server.
42- transform Run a specified code transformation on specified Luau files.
43- lint Run linting rules on specified Luau files.
42+ transform Run a specified code transformation on specified Luau files.
43+ lint Run linting rules on specified Luau files.
4444
4545Run Options (when using 'run' or no command):
4646 lute [run] <script.luau> [args...]
@@ -57,20 +57,20 @@ Compile Options:
5757Setup Options:
5858 lute setup
5959 Generates type definition files for the language server.
60- --with-luaurc Defines aliases to the type definition files in the working directory's luaurc file.
60+ --with-luaurc Defines aliases to the type definition files in the working directory's luaurc file.
6161
6262Transform Options:
63- lute transform <transformer script> [options...] <files...>
64- Runs the specified code transformation on the provided Luau files.
65- --dry-run Runs the transformation without actually overwriting or deleting any files.
66- --output <path> Specifies an output file for a transformed file. Only valid when
67- transforming a single file. If not specified, files are overwritten in place.
63+ lute transform <transformer script> [options...] <files...>
64+ Runs the specified code transformation on the provided Luau files.
65+ --dry-run Runs the transformation without actually overwriting or deleting any files.
66+ --output <path> Specifies an output file for a transformed file. Only valid when
67+ transforming a single file. If not specified, files are overwritten in place.
6868
6969Lint Options:
70- lute lint [options...] <paths...>
71- Runs linting rules on the specified Luau files.
72- --rules <path> Path to a single lint rule or a directory containing multiple lint rules.
73- If not specified, default lint rules are used.
70+ lute lint [options...] <paths...>
71+ Runs linting rules on the specified Luau files.
72+ --rules <path> Path to a single lint rule or a directory containing multiple lint rules.
73+ If not specified, default lint rules are used.
7474
7575General Options:
7676 -h, --help Display this usage message.
@@ -244,19 +244,23 @@ static std::pair<bool, std::string> getValidPath(std::string filePath)
244244 if (filePath.find (' .' ) != std::string::npos)
245245 return {false , res};
246246
247- std::string fallbackPath = joinPaths (" .lute" , filePath);
248- size_t fallbackSize = fallbackPath.size ();
247+ const std::array<std::string, 4 > fallbackPaths = {
248+ joinPaths (" .lute" , filePath + " .lua" ),
249+ joinPaths (" .lute" , filePath + " .luau" ),
250+ joinPaths (joinPaths (" .lute" , filePath), " init.lua" ),
251+ joinPaths (joinPaths (" .lute" , filePath), " init.luau" ),
252+ };
249253
250- for (const auto & ext : { " .luau " , " .lua " } )
254+ for (std::optional<std::string> currentPath = getCurrentWorkingDirectory (); currentPath; currentPath = getParentPath (*currentPath) )
251255 {
252- fallbackPath.resize (fallbackSize);
253- fallbackPath += ext;
254-
255- if (isFile (fallbackPath))
256- return {true , fallbackPath};
256+ for (const std::string& fallbackPath : fallbackPaths)
257+ {
258+ const std::string commandPath = joinPaths (*currentPath, fallbackPath);
259+ if (isFile (commandPath))
260+ return {true , commandPath};
261+ }
257262 }
258263
259-
260264 return {false , res};
261265}
262266
0 commit comments