Skip to content

Commit b7c08d8

Browse files
extract help_list
1 parent d1ee510 commit b7c08d8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

registry/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,20 @@ impl<R: 'static> Registry<R> {
126126
return opt;
127127
}
128128

129-
pub fn help_options<X: 'static>(&'static self, type_name: &str) -> OptionsPile<X> {
130-
let mut opt = OptionsPile::<X>::new();
131-
let list = &self.list;
132-
opt.match_zero(&[&format!("list-{}", type_name)], move |_p| {
133-
let lines: Vec<_> = list.iter().map(|data| (data.names[0], data.help_msg)).collect();
129+
pub fn help_list(&'static self) -> Vec<String> {
130+
let lines: Vec<_> = self.list.iter().map(|data| (data.names[0], data.help_msg)).collect();
134131

135-
let width = lines.iter().map(|(lhs, _rhs)| lhs.len()).max().unwrap();
132+
let width = lines.iter().map(|(lhs, _rhs)| lhs.len()).max().unwrap();
136133

137-
let lines = lines.iter().map(|(lhs, rhs)| format!("{:width$} {}", lhs, rhs, width = width)).collect();
134+
let lines = lines.iter().map(|(lhs, rhs)| format!("{:width$} {}", lhs, rhs, width = width)).collect();
138135

139-
return ValidationError::help(lines);
136+
return lines;
137+
}
138+
139+
pub fn help_options<X: 'static>(&'static self, type_name: &str) -> OptionsPile<X> {
140+
let mut opt = OptionsPile::<X>::new();
141+
opt.match_zero(&[&format!("list-{}", type_name)], move |_p| {
142+
return ValidationError::help(self.help_list());
140143
}, format!("list {}s", type_name));
141144
opt.match_single(&[&format!("show-{}", type_name)], move |_p, a| {
142145
let data = self.find_data(a)?;

0 commit comments

Comments
 (0)