From 94fe4b8ac099917ec9265f9c6d5ddf65ca3cdca3 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Mon, 9 Oct 2023 07:54:47 -0700 Subject: [PATCH 1/4] feat: support directories with init file for lune scripts --- .lune/other_dir_script/init.lua | 3 ++ .lune/some_dir_script/init.luau | 3 ++ src/cli/mod.rs | 1 + src/cli/utils/files.rs | 50 ++++++++++++++++++++++++++++++++- src/cli/utils/listing.rs | 40 ++++++++++++++++++++++++-- 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 .lune/other_dir_script/init.lua create mode 100644 .lune/some_dir_script/init.luau diff --git a/.lune/other_dir_script/init.lua b/.lune/other_dir_script/init.lua new file mode 100644 index 00000000..e5112134 --- /dev/null +++ b/.lune/other_dir_script/init.lua @@ -0,0 +1,3 @@ +--> Hello, there? + +print("Hello, world! -- from init.lua") diff --git a/.lune/some_dir_script/init.luau b/.lune/some_dir_script/init.luau new file mode 100644 index 00000000..2c645c74 --- /dev/null +++ b/.lune/some_dir_script/init.luau @@ -0,0 +1,3 @@ +--> Hello, there! + +print("Hello, world! -- from init.luau") diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 9a80c9d5..cb7daeeb 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -84,6 +84,7 @@ impl Cli { // This will also exit early and not run anything else if self.list { let sorted_relative = find_lune_scripts(false).await.map(sort_lune_scripts); + let sorted_home_dir = find_lune_scripts(true).await.map(sort_lune_scripts); if sorted_relative.is_err() && sorted_home_dir.is_err() { eprintln!("{}", sorted_relative.unwrap_err()); diff --git a/src/cli/utils/files.rs b/src/cli/utils/files.rs index 3bbf4a02..09e8a0d4 100644 --- a/src/cli/utils/files.rs +++ b/src/cli/utils/files.rs @@ -149,8 +149,56 @@ pub fn discover_script_path_including_lune_dirs(path: &str) -> Result { // directories + the home directory for the current user let res = discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), false) .or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), false)) + .or_else(|_| { + discover_script_path( + format!("lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.lua"), + false, + ) + }) + .or_else(|_| { + discover_script_path( + format!(".lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.lua"), + false, + ) + }) + .or_else(|_| { + discover_script_path( + format!("lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.luau"), + false, + ) + }) + .or_else(|_| { + discover_script_path( + format!(".lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.luau"), + false, + ) + }) .or_else(|_| discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), true)) - .or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), true)); + .or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), true)) + .or_else(|_| { + discover_script_path( + format!("lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.lua"), + true, + ) + }) + .or_else(|_| { + discover_script_path( + format!(".lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.lua"), + true, + ) + }) + .or_else(|_| { + discover_script_path( + format!("lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.luau"), + true, + ) + }) + .or_else(|_| { + discover_script_path( + format!(".lune{MAIN_SEPARATOR}{path}{MAIN_SEPARATOR}init.luau"), + true, + ) + }); match res { // NOTE: The first error message is generally more // descriptive than the ones for the lune subfolders diff --git a/src/cli/utils/listing.rs b/src/cli/utils/listing.rs index 63fd3a08..d3bd720a 100644 --- a/src/cli/utils/listing.rs +++ b/src/cli/utils/listing.rs @@ -1,3 +1,5 @@ +#![allow(clippy::match_same_arms)] + use std::{cmp::Ordering, ffi::OsStr, fmt::Write as _, path::PathBuf}; use anyhow::{bail, Result}; @@ -6,7 +8,7 @@ use directories::UserDirs; use once_cell::sync::Lazy; use tokio::{fs, io}; -use super::files::parse_lune_description_from_file; +use super::files::{discover_script_path, parse_lune_description_from_file}; pub static COLOR_BLUE: Lazy