Skip to content

Commit 1df5204

Browse files
actually reads from a specified file if you pass one
1 parent c21ec9e commit 1df5204

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/code.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11

2+
use std::process;
3+
use std::fs;
4+
use std::io;
5+
26
pub fn main(filename: &str) {
3-
println!("looks like {} is the file", filename);
7+
let contents : String;
8+
match fs::read_to_string(filename) {
9+
Ok(file_contents) => contents = file_contents,
10+
Err(e) => {
11+
eprintln!("Error reading file: {}", e);
12+
process::exit(1);
13+
},
14+
}
15+
run_file(contents);
16+
}
17+
18+
fn run_file(contents: String) {
19+
for line in contents.lines() {
20+
run_line(line.to_string());
21+
}
422
}
523

624
pub fn run_line(line: String) {

src/ie.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::code;
22
use std::io::{self, Write};
33

44
pub fn main() {
5+
println!("RustPython-v2 v1.0.0");
56
loop {
67
execution();
78
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod code;
22
mod ie;
33

44
use clap::Parser;
5+
use std::io;
56

67
#[derive(Parser)]
78
struct Args {

0 commit comments

Comments
 (0)