This pulls all of our long-form documentation into a single document, nicknamed "the book" and formally titled "The Rust Programming Language." A few things motivated this change: * People knew of The Guide, but not the individual Guides. This merges them together, helping discoverability. * You can get all of Rust's longform documentation in one place, which is nice. * We now have rustbook in-tree, which can generate this kind of documentation. While its style is basic, the general idea is much better: a table of contents on the left-hand side. * Rather than a almost 10,000-line guide.md, there are now smaller files per section.
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
//! Common API for all rust-book subcommands.
|
|
|
|
use error::CliResult;
|
|
use error::CommandResult;
|
|
use term::Term;
|
|
|
|
use help;
|
|
use build;
|
|
use serve;
|
|
use test;
|
|
|
|
pub trait Subcommand {
|
|
/// Mutate the subcommand by parsing its arguments.
|
|
///
|
|
/// Returns `Err` on a parsing error.
|
|
fn parse_args(&mut self, args: &[String]) -> CliResult<()>;
|
|
/// Print the CLI usage information.
|
|
fn usage(&self);
|
|
/// Actually execute the subcommand.
|
|
fn execute(&mut self, term: &mut Term) -> CommandResult<()>;
|
|
}
|
|
|
|
/// Create a Subcommand object based on its name.
|
|
pub fn parse_name(name: &str) -> Option<Box<Subcommand>> {
|
|
for parser in [
|
|
help::parse_cmd as fn(&str) -> Option<Box<Subcommand>>,
|
|
build::parse_cmd as fn(&str) -> Option<Box<Subcommand>>,
|
|
serve::parse_cmd as fn(&str) -> Option<Box<Subcommand>>,
|
|
test::parse_cmd as fn(&str) -> Option<Box<Subcommand>>].iter() {
|
|
let parsed = (*parser)(name);
|
|
if parsed.is_some() { return parsed }
|
|
}
|
|
None
|
|
}
|