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