From 7f7faf67b5f83f026212969a4c4a76e934f3de16 Mon Sep 17 00:00:00 2001 From: RudideC Date: Mon, 6 May 2024 09:44:23 +0200 Subject: [PATCH] Added arguments and modified .gitignore I added -h / --help and -f / --file so that the wyst code files aren't hard coded This makes it easier to test and debug --- .gitignore | 7 ++++++- Cargo.toml | 3 ++- src/main.rs | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 196e176..e9f6b6f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,10 @@ Cargo.lock # Added by cargo - /target + +#MacOS +.DS_Store + +#Wyst files for testing +*.wst \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index f5ca315..c953b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" [dependencies] regex = "1.10.4" -once_cell = "1.19.0" \ No newline at end of file +once_cell = "1.19.0" +clap = { version = "4.0", features = ["derive"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e6f310f..01642a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,21 @@ mod transpiler; mod parser; mod lexer; use std::fs; +use clap::Parser; +//Arguments for Wyst (short and long version) +#[derive(Parser)] +struct Args { + #[clap(short, long)] + file: String, +} + fn main() { - let code_file = "code.wst"; - let contents = fs::read_to_string(code_file).expect("cannot read for some reason"); - let result = transpiler::transpile(contents, 0); - println!("{result}") + let args = Args::parse(); + let file_content = fs::read_to_string(&args.file) + .expect("Error reading file"); + + let transpiled_code = transpiler::transpile(file_content, 0); + println!("{}", transpiled_code); } \ No newline at end of file