diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-08 09:21:57 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-08 09:21:57 -0800 |
| commit | cdc75bc34c3a281bf0c49c3a8a31bbe5f8d229d6 (patch) | |
| tree | adede39989a0cf04520bfc90a0b54cefdbfd5e18 /src/rustbook/subcommand.rs | |
| parent | 2f99a41fe1a27a48e96bc2616ec9faa6de924386 (diff) | |
| parent | 16a6ebd1f60871464c731306aa9007aab30f0dbf (diff) | |
| download | rust-cdc75bc34c3a281bf0c49c3a8a31bbe5f8d229d6.tar.gz rust-cdc75bc34c3a281bf0c49c3a8a31bbe5f8d229d6.zip | |
rollup merge of #19897: steveklabnik/trpl
An updated version of https://github.com/rust-lang/rust/pull/19461 This version vendors aturon/rust-book@731f7bf and builds it when building the docs. This is almost great, except my `make`-foo is poor, so I have my own personal paths in `mk/docs.mk`. How should I best get around that? /cc @brson
Diffstat (limited to 'src/rustbook/subcommand.rs')
| -rw-r--r-- | src/rustbook/subcommand.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/rustbook/subcommand.rs b/src/rustbook/subcommand.rs new file mode 100644 index 00000000000..473739c919d --- /dev/null +++ b/src/rustbook/subcommand.rs @@ -0,0 +1,44 @@ +// 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 +} |
