summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index f87b69d..98b49ed 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -82,7 +82,7 @@ fn repl(away: &mut Arc<Mutex<bool>>, env: &mut Environment) {
}
}
-fn options() {
+fn options(env: &mut Environment) {
let args: Vec<String> = env::args().collect();
for arg in args.iter() {
if arg.eq("--version") {
@@ -94,6 +94,33 @@ fn options() {
std::process::exit(0);
}
}
+
+ match args.last() {
+ Some(arg) => {
+ if args.len() > 1 && !arg.starts_with('-') {
+ let poetry = std::fs::read_to_string(arg)
+ .expect(format!("dwvsh: can't open input file: {}", arg).as_str());
+ let poem = Poem::read(poetry, env);
+ let poem = match poem {
+ Ok(poem) => poem,
+ Err(e) => {
+ eprintln!("dwvsh: {}", e.to_string().to_lowercase());
+ std::process::exit(1);
+ }
+ };
+
+ // Recite the poem
+ match poem.recite(env) {
+ Ok(_) => {}
+ Err(e) => eprintln!("dwvsh: {}", e.to_string().to_lowercase()),
+ }
+
+ // Quit
+ std::process::exit(0);
+ }
+ }
+ None => {}
+ }
}
/// Shell entry
@@ -123,7 +150,7 @@ fn main() {
};
// Parse flags and other arguments
- options();
+ options(&mut env);
// Begin evaluating commands
repl(&mut away, &mut env);