diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ca914..e1c753b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added support for running directories with an `init.luau` or `init.lua` file in them in the CLI + ### Fixed - Fixed crashes when writing a very deeply nested `Instance` to a file ([#62]) diff --git a/packages/cli/src/cli.rs b/packages/cli/src/cli.rs index 9d26e06..63b9d87 100644 --- a/packages/cli/src/cli.rs +++ b/packages/cli/src/cli.rs @@ -12,7 +12,7 @@ use tokio::{ use crate::{ setup::run_setup, utils::{ - files::{discover_script_file_path_including_lune_dirs, strip_shebang}, + files::{discover_script_path_including_lune_dirs, strip_shebang}, listing::{find_lune_scripts, sort_lune_scripts, write_lune_scripts_list}, }, }; @@ -163,7 +163,7 @@ impl Cli { .context("Failed to read script contents from stdin")?; ("stdin".to_string(), stdin_contents) } else { - let file_path = discover_script_file_path_including_lune_dirs(&script_path)?; + let file_path = discover_script_path_including_lune_dirs(&script_path)?; let file_contents = read_to_vec(&file_path).await?; // NOTE: We skip the extension here to remove it from stack traces let file_display_name = file_path.with_extension("").display().to_string(); diff --git a/packages/cli/src/utils/files.rs b/packages/cli/src/utils/files.rs index 5be816a..3bbf4a0 100644 --- a/packages/cli/src/utils/files.rs +++ b/packages/cli/src/utils/files.rs @@ -35,7 +35,7 @@ static ERR_MESSAGE_HELP_NOTE: Lazy = Lazy::new(|| { 1. If we got a file that definitely exists, make sure it is either - using an absolute path - has the lua or luau extension - 2. If we got a directory, let the user know + 2. If we got a directory, check if it has an `init` file to use, and if it doesn't, let the user know 3. If we got an absolute path, don't check any extensions, just let the user know it didn't exist 4. If we got a relative path with no extension, also look for a file with a lua or luau extension 5. No other options left, the file simply did not exist @@ -44,10 +44,11 @@ static ERR_MESSAGE_HELP_NOTE: Lazy = Lazy::new(|| { path, and that they then have control over script discovery behavior, whereas if they pass in a relative path we will instead try to be as permissive as possible for user-friendliness */ -pub fn discover_script_file_path(path: &str, in_home_dir: bool) -> Result { +pub fn discover_script_path(path: impl AsRef, in_home_dir: bool) -> Result { // NOTE: We don't actually support any platforms without home directories, // but just in case the user has some strange configuration and it cannot // be found we should at least throw a nice error instead of panicking + let path = path.as_ref(); let file_path = if in_home_dir { match UserDirs::new() { Some(dirs) => dirs.home_dir().join(path), @@ -89,10 +90,16 @@ pub fn discover_script_file_path(path: &str, in_home_dir: bool) -> Result Ok(path), + _ => Err(anyhow!( + "No file was found at {}, found a directory without an init file", + style(file_path.display()).yellow() + )), + } } else if is_abs && !in_home_dir { Err(anyhow!( "No file was found at {}", @@ -128,8 +135,8 @@ pub fn discover_script_file_path(path: &str, in_home_dir: bool) -> Result Result { - match discover_script_file_path(path, false) { +pub fn discover_script_path_including_lune_dirs(path: &str) -> Result { + match discover_script_path(path, false) { Ok(path) => Ok(path), Err(e) => { // If we got any absolute path it means the user has also @@ -140,16 +147,10 @@ pub fn discover_script_file_path_including_lune_dirs(path: &str) -> Result