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