]> git.lizzy.rs Git - rust.git/blob - src/rustbook/main.rs
ea72c653087d39a7bfbd371630d97be4bb6abe74
[rust.git] / src / rustbook / main.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(slicing_syntax, box_syntax)]
12 #![allow(unstable)]
13
14 extern crate regex;
15
16 extern crate rustdoc;
17
18 use std::os;
19 use subcommand::Subcommand;
20 use term::Term;
21
22 macro_rules! try (
23     ($expr:expr) => ({
24         use error;
25         match $expr {
26             Ok(val) => val,
27             Err(err) => return Err(error::FromError::from_err(err))
28         }
29     })
30 );
31
32 mod term;
33 mod error;
34 mod book;
35
36 mod subcommand;
37 mod help;
38 mod build;
39 mod serve;
40 mod test;
41
42 mod css;
43 mod javascript;
44
45 #[cfg(not(test))] // thanks #12327
46 fn main() {
47     let mut term = Term::new();
48     let cmd = os::args();
49
50     if cmd.len() < 1 {
51         help::usage()
52     } else {
53         match subcommand::parse_name(&cmd[1][]) {
54             Some(mut subcmd) => {
55                 match subcmd.parse_args(cmd.tail()) {
56                     Ok(_) => {
57                         match subcmd.execute(&mut term) {
58                             Ok(_) => (),
59                             Err(err) => {
60                                 term.err(&format!("error: {}", err.description())[]);
61                                 err.detail().map(|detail| {
62                                     term.err(&format!("detail: {}", detail)[]);
63                                 });
64                             }
65                         }
66                     }
67                     Err(err) => {
68                         println!("{}", err.description());
69                         println!("");
70                         subcmd.usage();
71                     }
72                 }
73             }
74             None => {
75                 println!("Unrecognized command '{}'.", cmd[1]);
76                 println!("");
77                 help::usage();
78             }
79         }
80     }
81 }