Add cli args for downloading selene & luau type definitions

This commit is contained in:
Filip Tibell 2023-01-19 00:36:44 -05:00
parent 67235f436a
commit b6a784add8
No known key found for this signature in database

View file

@ -12,10 +12,30 @@ use crate::lune::{fs::LuneFs, json::LuneJson, process::LuneProcess};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
pub struct Cli { pub struct Cli {
/// Path to the file to run /// Path to the file to run, or the name
path: String, /// of a luau file in a lune directory
/// Arguments to pass to the file script_path: String,
args: Vec<String>, /// Arguments to pass to the file as vararg (...)
script_args: Vec<String>,
/// 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 { impl Cli {
@ -25,8 +45,8 @@ impl Cli {
S: Into<String>, S: Into<String>,
{ {
Self { Self {
path: path.into(), script_path: path.into(),
args: vec![], ..Default::default()
} }
} }
@ -37,14 +57,15 @@ impl Cli {
A: Into<Vec<String>>, A: Into<Vec<String>>,
{ {
Self { Self {
path: path.into(), script_path: path.into(),
args: args.into(), script_args: args.into(),
..Default::default()
} }
} }
pub async fn run(self) -> Result<()> { pub async fn run(self) -> Result<()> {
// Parse and read the wanted file // 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)?; let file_contents = read_to_string(file_path)?;
// Create a new lua state and add in all lune globals // Create a new lua state and add in all lune globals
let lua = Lua::new(); let lua = Lua::new();
@ -55,7 +76,7 @@ impl Cli {
lua.sandbox(true)?; lua.sandbox(true)?;
// Load & call the file with the given args // Load & call the file with the given args
let lua_args = self let lua_args = self
.args .script_args
.iter() .iter()
.map(|value| value.to_owned().to_lua(&lua)) .map(|value| value.to_owned().to_lua(&lua))
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;