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