| ... | ... | @@ -26,12 +26,15 @@ enum Commands { |
| 26 | 26 | // Whether to output to stdout instead of a file |
| 27 | 27 | #[arg(long, default_value_t = false)] |
| 28 | 28 | stdout: bool, |
| 29 | /// What javascript runtime to compile to |
| 30 | #[arg(short, long, default_value = "deno")] |
| 31 | target: String, |
| 29 | 32 | }, |
| 30 | 33 | Run { |
| 31 | 34 | file: PathBuf, |
| 32 | | /// What javascript runtime to use |
| 35 | /// What javascript runtime to compile to and use |
| 33 | 36 | #[arg(short, long, default_value = "deno")] |
| 34 | | runtime: String, |
| 37 | target: String, |
| 35 | 38 | }, |
| 36 | 39 | } |
| 37 | 40 | |
| ... | ... | @@ -63,7 +66,7 @@ fn main() -> Result<()> { |
| 63 | 66 | let cli = Cli::parse(); |
| 64 | 67 | |
| 65 | 68 | match cli.command { |
| 66 | | Commands::Compile { file, stdout } => { |
| 69 | Commands::Compile { file, stdout, target: _ } => { |
| 67 | 70 | let contents = std::fs::read_to_string(file.clone()).unwrap(); |
| 68 | 71 | let result = transpile(contents.clone())?; |
| 69 | 72 | |
| ... | ... | @@ -73,14 +76,14 @@ fn main() -> Result<()> { |
| 73 | 76 | std::fs::write(file.with_extension("js"), result).unwrap(); |
| 74 | 77 | } |
| 75 | 78 | } |
| 76 | | Commands::Run { file, runtime } => { |
| 79 | Commands::Run { file, target } => { |
| 77 | 80 | let contents = std::fs::read_to_string(file.clone()).unwrap(); |
| 78 | 81 | let result = transpile(contents.clone())?; |
| 79 | 82 | let mut temp_file = std::env::temp_dir(); |
| 80 | 83 | temp_file.push("temp.js"); |
| 81 | 84 | std::fs::write(temp_file.clone(), result).unwrap(); |
| 82 | 85 | |
| 83 | | let rt = get_runtime(&runtime); |
| 86 | let rt = get_runtime(&target); |
| 84 | 87 | |
| 85 | 88 | match rt.as_str() { |
| 86 | 89 | "deno" => { |
| ... | ... | @@ -108,7 +111,7 @@ fn main() -> Result<()> { |
| 108 | 111 | println!("{}", String::from_utf8_lossy(&output.stdout)); |
| 109 | 112 | } |
| 110 | 113 | _ => { |
| 111 | | println!("Unknown runtime: {}", runtime); |
| 114 | println!("Unknown runtime: {}", target); |
| 112 | 115 | } |
| 113 | 116 | } |
| 114 | 117 | } |