Skip to content

Commit

Permalink
doc: test: Fix panic in doc example
Browse files Browse the repository at this point in the history
The exmaple provided in src/lib.rs panics because the code attempts look
for debug args when the interface does not have one. Fix this issue by
guarding these calls with the bool self.ifc_debug which indactes the
presnesce of those options.

Fixes: tkeksa#4
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
  • Loading branch information
sidcha committed Jun 29, 2024
1 parent dd31a7d commit c41da02
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,18 @@ impl<'a> Extcap<'a> {
};

// Log initialization
let debug = self.get_matches().is_present(OPT_DEBUG);
let debug_file = self.get_matches().value_of(OPT_DEBUG_FILE).and_then(|s| {
if s.trim().is_empty() {
None
} else {
Some(s)
}
});
let debug = self.ifc_debug && self.get_matches().contains_id(OPT_DEBUG);
let debug_file = if self.ifc_debug {
self.get_matches().value_of(OPT_DEBUG_FILE).and_then(|s| {
if s.trim().is_empty() {
None
} else {
Some(s)
}
})
} else {
None
};
listener.init_log(self, debug, debug_file);
debug!("=======================");
debug!(
Expand Down

0 comments on commit c41da02

Please sign in to comment.