]> git.lizzy.rs Git - rust.git/blob - src/rustbook/main.rs
4a652f846ed58bd0112c54e609a64737c8dad74f
[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 #![deny(warnings)]
12
13 #![feature(core)]
14 #![feature(exit_status)]
15 #![feature(rustdoc)]
16 #![feature(rustc_private)]
17 #![feature(path_relative_from)]
18 #![feature(convert)]
19
20 extern crate rustdoc;
21 extern crate rustc_back;
22
23 use std::env;
24 use std::error::Error;
25 use subcommand::Subcommand;
26 use term::Term;
27
28 mod term;
29 mod error;
30 mod book;
31
32 mod subcommand;
33 mod help;
34 mod build;
35 mod serve;
36 mod test;
37
38 mod css;
39 mod javascript;
40
41 #[cfg(not(test))] // thanks #12327
42 fn main() {
43     let mut term = Term::new();
44     let cmd: Vec<_> = env::args().collect();
45
46     if cmd.len() <= 1 {
47         help::usage()
48     } else {
49         match subcommand::parse_name(&cmd[1][..]) {
50             Some(mut subcmd) => {
51                 match subcmd.parse_args(&cmd[..cmd.len()-1]) {
52                     Ok(_) => {
53                         match subcmd.execute(&mut term) {
54                             Ok(_) => (),
55                             Err(err) => {
56                                 term.err(&format!("error: {}", err));
57                             }
58                         }
59                     }
60                     Err(err) => {
61                         println!("{}", err.description());
62                         println!("");
63                         subcmd.usage();
64                     }
65                 }
66             }
67             None => {
68                 println!("Unrecognized command '{}'.", cmd[1]);
69                 println!("");
70                 help::usage();
71             }
72         }
73     }
74 }