about summary refs log tree commit diff
path: root/src/rustbook/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rustbook/main.rs')
-rw-r--r--src/rustbook/main.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs
new file mode 100644
index 00000000000..acb4edb7a45
--- /dev/null
+++ b/src/rustbook/main.rs
@@ -0,0 +1,74 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(slicing_syntax, box_syntax)]
+
+extern crate regex;
+
+extern crate rustdoc;
+
+use std::os;
+use subcommand::Subcommand;
+use term::Term;
+
+macro_rules! try (
+    ($expr:expr) => ({
+        use error;
+        match $expr {
+            Ok(val) => val,
+            Err(err) => return Err(error::FromError::from_err(err))
+        }
+    })
+);
+
+mod term;
+mod error;
+mod book;
+
+mod subcommand;
+mod help;
+mod build;
+mod serve;
+mod test;
+
+mod css;
+
+#[cfg(not(test))] // thanks #12327
+fn main() {
+    let mut term = Term::new();
+    let cmd = os::args();
+
+    if cmd.len() < 1 {
+        help::usage()
+    } else {
+        match subcommand::parse_name(&cmd[1][]) {
+            Some(mut subcmd) => {
+                match subcmd.parse_args(cmd.tail()) {
+                    Ok(_) => {
+                        match subcmd.execute(&mut term) {
+                            Ok(_) => (),
+                            Err(_) => os::set_exit_status(-1),
+                        }
+                    }
+                    Err(err) => {
+                        println!("{}", err.description());
+                        println!("");
+                        subcmd.usage();
+                    }
+                }
+            }
+            None => {
+                println!("Unrecognized command '{}'.", cmd[1]);
+                println!("");
+                help::usage();
+            }
+        }
+    }
+}