From b6a784add857ada6c31ac14ca7c5a1c8e2967c4f Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 19 Jan 2023 00:36:44 -0500 Subject: [PATCH] Add cli args for downloading selene & luau type definitions --- src/cli.rs | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index fb568dd..8774cca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,10 +12,30 @@ use crate::lune::{fs::LuneFs, json::LuneJson, process::LuneProcess}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Cli { - /// Path to the file to run - path: String, - /// Arguments to pass to the file - args: Vec, + /// Path to the file to run, or the name + /// of a luau file in a lune directory + script_path: String, + /// Arguments to pass to the file as vararg (...) + script_args: Vec, + /// Pass this flag to download the Selene type + /// definitions file to the current directory + #[clap(long)] + download_selene_types: bool, + /// Pass this flag to download the Luau type + /// definitions file to the current directory + #[clap(long)] + download_luau_types: bool, +} + +impl Default for Cli { + fn default() -> Self { + Self { + script_path: "".to_string(), + script_args: vec![], + download_selene_types: false, + download_luau_types: false, + } + } } impl Cli { @@ -25,8 +45,8 @@ impl Cli { S: Into, { Self { - path: path.into(), - args: vec![], + script_path: path.into(), + ..Default::default() } } @@ -37,14 +57,15 @@ impl Cli { A: Into>, { Self { - path: path.into(), - args: args.into(), + script_path: path.into(), + script_args: args.into(), + ..Default::default() } } pub async fn run(self) -> Result<()> { // Parse and read the wanted file - let file_path = find_parse_file_path(&self.path)?; + let file_path = find_parse_file_path(&self.script_path)?; let file_contents = read_to_string(file_path)?; // Create a new lua state and add in all lune globals let lua = Lua::new(); @@ -55,7 +76,7 @@ impl Cli { lua.sandbox(true)?; // Load & call the file with the given args let lua_args = self - .args + .script_args .iter() .map(|value| value.to_owned().to_lua(&lua)) .collect::>>()?;