diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-01-07 15:17:16 +0000 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-01-08 09:21:15 -0800 |
commit | 0b673f2f0184efa0111c4978a2a4159598dee7a6 (patch) | |
tree | 4e420e4f6359d1f258ab3fd285de56ad81a13760 /argparse/src/help.rs | |
parent | 8482335491aa55b0458ffedccd1fc110f092e38a (diff) | |
download | nitrocli-0b673f2f0184efa0111c4978a2a4159598dee7a6.tar.gz nitrocli-0b673f2f0184efa0111c4978a2a4159598dee7a6.tar.bz2 |
Remove argparse dependency
As we have replaced argparse with structopt, we no longer need it as a
dependency. This patch removes the dependency from Cargo.toml and
deletes the included copy.
Delete subrepo argparse/:argparse
Diffstat (limited to 'argparse/src/help.rs')
-rw-r--r-- | argparse/src/help.rs | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/argparse/src/help.rs b/argparse/src/help.rs deleted file mode 100644 index c7145be..0000000 --- a/argparse/src/help.rs +++ /dev/null @@ -1,93 +0,0 @@ -use std::str::CharIndices; -use std::io::Result as IoResult; -use std::io::Write; - -use super::action::{IFlagAction, ParseResult}; -use super::action::ParseResult::Help; - -pub struct HelpAction; - -impl IFlagAction for HelpAction { - fn parse_flag(&self) -> ParseResult { - return Help; - } -} - - -struct WordsIter<'a> { - data: &'a str, - iter: CharIndices<'a>, -} - -impl<'a> WordsIter<'a> { - fn new(data: &'a str) -> WordsIter<'a> { - return WordsIter { - data: data, - iter: data.char_indices(), - }; - } -} - -impl<'a> Iterator for WordsIter<'a> { - type Item = &'a str; - fn next(&mut self) -> Option<&'a str> { - let word_start; - loop { - let (idx, ch) = match self.iter.next() { - None => return None, - Some((idx, ch)) => ((idx, ch)), - }; - match ch { - ' ' | '\t' | '\r' | '\n' => continue, - _ => { - word_start = idx; - break; - } - } - } - loop { - let (idx, ch) = match self.iter.next() { - None => break, - Some((idx, ch)) => ((idx, ch)), - }; - match ch { - ' ' | '\t' | '\r' | '\n' => { - return Some(&self.data[word_start..idx]); - } - _ => continue, - } - } - return Some(&self.data[word_start..self.data.len()]); - } -} - -pub fn wrap_text(buf: &mut Write, data: &str, width: usize, indent: usize) - -> IoResult<()> -{ - let mut witer = WordsIter::new(data); - let mut off = indent; - match witer.next() { - None => { - return Ok(()); - } - Some(word) => { - try!(buf.write(word.as_bytes())); - off += word.len(); - } - } - for word in witer { - if off + word.len() + 1 > width { - try!(buf.write(b"\n")); - for _ in 0..indent { - try!(buf.write(b" ")); - } - off = indent; - } else { - try!(buf.write(b" ")); - off += 1; - } - try!(buf.write(word.as_bytes())); - off += word.len(); - } - return Ok(()); -} |