Skip to content

Commit 9e3972d

Browse files
authored
Merge pull request #52 from LunaStev/develop
Add Wave Version and Update CLI Description
2 parents 86872bd + 5c9b6ae commit 9e3972d

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "Wave"
3-
version = "0.1.0"
2+
name = "wave"
3+
version = "0.0.2-pre-alpha"
44
edition = "2021"
55

66
[dependencies]

src/main.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,42 @@ fn format_ast(ast: &AST) -> String {
4141
}
4242
*/
4343

44+
const VERSION: &str = env!("CARGO_PKG_VERSION");
45+
4446
fn main() {
4547
let args: Vec<String> = env::args().collect();
4648

4749
if args.len() < 2 {
48-
eprintln!("Usage: {} <path_to_wave_file>", args[0]);
50+
eprintln!("Usage: wave <command> [arguments]");
51+
eprintln!("Commands:");
52+
eprintln!(" run <file> Execute the specified Wave file");
53+
eprintln!(" --version Show the CLI version");
4954
process::exit(1);
5055
}
5156

52-
let file_path = &args[1];
57+
match args[1].as_str() {
58+
"--version" => {
59+
println!("v{}", VERSION);
60+
return;
61+
}
62+
"run" => {
63+
if args.len() < 3 {
64+
eprintln!("Usage: wave run <file>");
65+
process::exit(1);
66+
}
67+
68+
let file_path = &args[2];
69+
run_wave_file(file_path);
70+
}
71+
_ => {
72+
eprintln!("Unknown command: {}", args[1]);
73+
eprintln!("Use 'wave --version' or 'wave run <file>'");
74+
process::exit(1);
75+
}
76+
}
77+
}
5378

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

67-
let function_name = tokens.iter()
93+
let function_name = tokens
94+
.iter()
6895
.find(|token| matches!(token.token_type, TokenType::IDENTIFIER(_)))
6996
.map(|token| token.lexeme.clone())
7097
.unwrap_or_default();

0 commit comments

Comments
 (0)