Skip to content

Commit

Permalink
Merge pull request #52 from LunaStev/develop
Browse files Browse the repository at this point in the history
Add Wave Version and Update CLI Description
  • Loading branch information
LunaStev authored Jan 15, 2025
2 parents 86872bd + 5c9b6ae commit 9e3972d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Wave"
version = "0.1.0"
name = "wave"
version = "0.0.2-pre-alpha"
edition = "2021"

[dependencies]
33 changes: 30 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,42 @@ fn format_ast(ast: &AST) -> String {
}
*/

const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() {
let args: Vec<String> = env::args().collect();

if args.len() < 2 {
eprintln!("Usage: {} <path_to_wave_file>", args[0]);
eprintln!("Usage: wave <command> [arguments]");
eprintln!("Commands:");
eprintln!(" run <file> Execute the specified Wave file");
eprintln!(" --version Show the CLI version");
process::exit(1);
}

let file_path = &args[1];
match args[1].as_str() {
"--version" => {
println!("v{}", VERSION);
return;
}
"run" => {
if args.len() < 3 {
eprintln!("Usage: wave run <file>");
process::exit(1);
}

let file_path = &args[2];
run_wave_file(file_path);
}
_ => {
eprintln!("Unknown command: {}", args[1]);
eprintln!("Use 'wave --version' or 'wave run <file>'");
process::exit(1);
}
}
}

fn run_wave_file(file_path: &str) {
let code = match fs::read_to_string(file_path) {
Ok(content) => content,
Err(err) => {
Expand All @@ -64,7 +90,8 @@ fn main() {
let tokens = lexer.tokenize();
eprintln!("Tokens: {}", format_tokens(&tokens));

let function_name = tokens.iter()
let function_name = tokens
.iter()
.find(|token| matches!(token.token_type, TokenType::IDENTIFIER(_)))
.map(|token| token.lexeme.clone())
.unwrap_or_default();
Expand Down

0 comments on commit 9e3972d

Please sign in to comment.