|
| 1 | +use opts::parser::OptionsPile; |
| 2 | +use opts::parser::Optionsable; |
| 3 | +use opts::vals::OptionalStringOption; |
| 4 | +use std::sync::Arc; |
| 5 | +use stream::Stream; |
| 6 | +use super::OperationBe; |
| 7 | +use super::OperationRegistrant; |
| 8 | +use validates::Validates; |
| 9 | +use validates::ValidationError; |
| 10 | +use validates::ValidationResult; |
| 11 | + |
| 12 | +#[derive(Default)] |
| 13 | +pub struct Options { |
| 14 | + name: OptionalStringOption, |
| 15 | +} |
| 16 | + |
| 17 | +pub enum Void { |
| 18 | +} |
| 19 | + |
| 20 | +impl Validates for Options { |
| 21 | + type Target = Void; |
| 22 | + |
| 23 | + fn validate(self) -> ValidationResult<Void> { |
| 24 | + let name = self.name.validate()?; |
| 25 | + return ValidationError::help(match name { |
| 26 | + Some(name) => super::REGISTRY.find(&name, &[])?.help(), |
| 27 | + None => super::REGISTRY.help_list(), |
| 28 | + }); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +pub(crate) type Impl = OperationRegistrant<ImplBe>; |
| 33 | + |
| 34 | +pub(crate) struct ImplBe(); |
| 35 | + |
| 36 | +impl Optionsable for ImplBe { |
| 37 | + type Options = Options; |
| 38 | + |
| 39 | + fn options(opt: &mut OptionsPile<Options>) { |
| 40 | + opt.match_extra_soft(|p, a| p.name.maybe_set_str(a), "operation to show help for"); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +impl OperationBe for ImplBe { |
| 45 | + fn names() -> Vec<&'static str> { |
| 46 | + return vec!["help"]; |
| 47 | + } |
| 48 | + |
| 49 | + fn help_msg() -> &'static str { |
| 50 | + return "show help for an operation"; |
| 51 | + } |
| 52 | + |
| 53 | + fn get_extra(_o: Arc<Void>) -> Vec<String> { |
| 54 | + panic!(); |
| 55 | + } |
| 56 | + |
| 57 | + fn stream(_o: Arc<Void>) -> Stream { |
| 58 | + panic!(); |
| 59 | + } |
| 60 | +} |
0 commit comments