cmd_args/option/
descriptor.rs

1use std::rc::Rc;
2use crate::option;
3use std::collections::HashSet;
4
5/// Description of an option.
6pub struct Descriptor {
7    name: Rc<String>,
8    aliases: HashSet<String>,
9    value_type: option::Type,
10    description: String,
11}
12
13impl Descriptor {
14    /// Create a new option descriptor.
15    pub fn new(name: &str, value_type: option::Type, description: &str) -> Self {
16        Descriptor {
17            name: Rc::new(String::from(name)),
18            aliases: HashSet::new(),
19            value_type,
20            description: String::from(description),
21        }
22    }
23
24    /// Get the name of the option.
25    pub fn name(&self) -> &String {
26        &self.name
27    }
28
29    /// Take a reference to the name of the option.
30    pub fn take_name(&self) -> Rc<String> {
31        Rc::clone(&self.name)
32    }
33
34    /// Get the type of the option value.
35    pub fn value_type(&self) -> &option::Type {
36        &self.value_type
37    }
38
39    /// Get the description of the option.
40    pub fn description(&self) -> &String {
41        &self.description
42    }
43
44    /// Add an alias to the option.
45    pub fn add_alias(mut self, alias: &str) -> Self {
46        self.aliases.insert(String::from(alias));
47
48        self
49    }
50
51    /// Get aliases.
52    pub fn get_aliases(&self) -> &HashSet<String> {
53        &self.aliases
54    }
55}