]> git.lizzy.rs Git - rust.git/blob - src/rustbook/main.rs
rollup merge of #21151: brson/beta
[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
13 extern crate regex;
14
15 extern crate rustdoc;
16
17 use std::os;
18 use subcommand::Subcommand;
19 use term::Term;
20
21 macro_rules! try (
22     ($expr:expr) => ({
23         use error;
24         match $expr {
25             Ok(val) => val,
26             Err(err) => return Err(error::FromError::from_err(err))
27         }
28     })
29 );
30
31 mod term;
32 mod error;
33 mod book;
34
35 mod subcommand;
36 mod help;
37 mod build;
38 mod serve;
39 mod test;
40
41 mod css;
42 mod javascript;
43
44 #[cfg(not(test))] // thanks #12327
45 fn main() {
46     let mut term = Term::new();
47     let cmd = os::args();
48
49     if cmd.len() < 1 {
50         help::usage()
51     } else {
52         match subcommand::parse_name(&cmd[1][]) {
53             Some(mut subcmd) => {
54                 match subcmd.parse_args(cmd.tail()) {
55                     Ok(_) => {
56                         match subcmd.execute(&mut term) {
57                             Ok(_) => (),
58                             Err(err) => {
59                                 term.err(&format!("error: {}", err.description())[]);
60                                 err.detail().map(|detail| {
61                                     term.err(&format!("detail: {}", detail)[]);
62                                 });
63                             }
64                         }
65                     }
66                     Err(err) => {
67                         println!("{}", err.description());
68                         println!("");
69                         subcmd.usage();
70                     }
71                 }
72             }
73             None => {
74                 println!("Unrecognized command '{}'.", cmd[1]);
75                 println!("");
76                 help::usage();
77             }
78         }
79     }
80 }