|
| 1 | +use clap::ArgMatches; |
1 | 2 | use colored::*; |
2 | 3 | use dirs::home_dir; |
3 | 4 | use glob::glob; |
@@ -115,9 +116,9 @@ fn parse_doc<'a>(input: &'a str, delims: Delimiters) -> IResult<&'a str, Doc> { |
115 | 116 | >> (Doc { |
116 | 117 | short_description: short.to_string(), |
117 | 118 | long_description: long.unwrap_or("").to_string(), |
118 | | - descriptors: desc.unwrap_or(Vec::new()), |
119 | | - params: par.unwrap_or(Vec::new()), |
120 | | - returns: ret.unwrap_or(Vec::new()), |
| 119 | + descriptors: desc.unwrap_or_default(), |
| 120 | + params: par.unwrap_or_default(), |
| 121 | + returns: ret.unwrap_or_default(), |
121 | 122 | }) |
122 | 123 | ) |
123 | 124 | } |
@@ -364,20 +365,26 @@ impl<'a> Default for Delimiters<'a> { |
364 | 365 |
|
365 | 366 | impl<'a> Delimiters<'a> { |
366 | 367 | /// Override default delimiters with passed in values |
367 | | - pub fn override_delims(overrides: String) -> Self { |
| 368 | + pub fn override_delims(overrides: &'a ArgMatches<'a>) -> Self { |
368 | 369 | let mut result: Delimiters = Delimiters::default(); |
369 | | - let splitted: Vec<_> = Box::leak(overrides.into_boxed_str()) |
370 | | - .split_whitespace() |
371 | | - .collect(); |
372 | | - if splitted.len() != 6 { |
373 | | - panic!("Please enter the proper number of delimiters"); |
| 370 | + if overrides.is_present("start") { |
| 371 | + result.start = overrides.value_of("start").unwrap(); |
| 372 | + } |
| 373 | + if overrides.is_present("end") { |
| 374 | + result.end = overrides.value_of("end").unwrap(); |
| 375 | + } |
| 376 | + if overrides.is_present("descriptor") { |
| 377 | + result.opt = overrides.value_of("descriptor").unwrap(); |
| 378 | + } |
| 379 | + if overrides.is_present("params") { |
| 380 | + result.params = overrides.value_of("params").unwrap(); |
| 381 | + } |
| 382 | + if overrides.is_present("returns") { |
| 383 | + result.ret = overrides.value_of("returns").unwrap(); |
| 384 | + } |
| 385 | + if overrides.is_present("comment") { |
| 386 | + result.comm = overrides.value_of("comment").unwrap(); |
374 | 387 | } |
375 | | - result.start = &splitted[0]; |
376 | | - result.end = &splitted[1]; |
377 | | - result.params = &splitted[2]; |
378 | | - result.ret = &splitted[3]; |
379 | | - result.opt = &splitted[4]; |
380 | | - result.comm = &splitted[5]; |
381 | 388 | result |
382 | 389 | } |
383 | 390 |
|
|
0 commit comments