diff --git a/jaarg/src/alloc.rs b/jaarg/src/alloc.rs index 1e732a0..784ed39 100644 --- a/jaarg/src/alloc.rs +++ b/jaarg/src/alloc.rs @@ -17,7 +17,7 @@ impl Opts<&'static str> { help: impl Fn(&str), error: impl FnOnce(&str, ParseError) ) -> ParseMapResult { let mut out: BTreeMap<&'static str, String> = BTreeMap::new(); - match self.parse(&program_name, args, |_program_name, id, opt, _name, arg| { + match self.parse(program_name, args, |_program_name, id, opt, _name, arg| { if opt.is_help() { help(program_name); Ok(ParseControl::Quit) diff --git a/jaarg/src/argparse.rs b/jaarg/src/argparse.rs index 938a2b5..de6a7ff 100644 --- a/jaarg/src/argparse.rs +++ b/jaarg/src/argparse.rs @@ -3,6 +3,10 @@ * SPDX-License-Identifier: MIT OR Apache-2.0 */ +use crate::{Opt, Opts}; +use crate::option::OptType; +use crate::options::RequiredParamsBitSet; + /// Enum describing the result of parsing arguments, and how the program should behave. #[derive(Debug)] pub enum ParseResult { @@ -25,7 +29,7 @@ pub enum ParseControl { } /// Result type used by the handler passed to the parser. -type HandlerResult<'a, T> = core::result::Result>; +pub(crate) type HandlerResult<'a, T> = core::result::Result>; #[derive(Debug)] pub enum ParseError<'a> { diff --git a/jaarg/src/help.rs b/jaarg/src/help.rs index 6d2b3f1..c697945 100644 --- a/jaarg/src/help.rs +++ b/jaarg/src/help.rs @@ -3,6 +3,9 @@ * SPDX-License-Identifier: MIT OR Apache-2.0 */ +use crate::{Opt, Opts, ParseError}; +use crate::option::{OptIdentifier, OptType}; + /// Enough context to show full help text. pub struct HelpWriterContext<'a, ID: 'static> { pub options: &'a Opts, @@ -166,7 +169,7 @@ impl core::fmt::Display for StandardFullHelpWriter<'_, ID> { } // Write line for option, with aligned help text if needed - let line = OptionUsageLine(&option); + let line = OptionUsageLine(option); if let Some(help_text) = option.help_string { write!(f, " {line:. { - id: ID, - names: OptIdentifier, - value_name: Option<&'static str>, - help_string: Option<&'static str>, - r#type: OptType, + pub(crate) id: ID, + pub(crate) names: OptIdentifier, + pub(crate) value_name: Option<&'static str>, + pub(crate) help_string: Option<&'static str>, + pub(crate) r#type: OptType, flags: OptFlag, } @@ -122,12 +124,12 @@ impl Opt { } #[inline(always)] - const fn is_short_visible(&self) -> bool { + pub(crate) const fn is_short_visible(&self) -> bool { (self.flags.0 & OptFlag::VISIBLE_SHORT.0) != 0 } #[inline(always)] - const fn is_full_visible(&self) -> bool { + pub(crate) const fn is_full_visible(&self) -> bool { (self.flags.0 & OptFlag::VISIBLE_FULL.0) != 0 } } @@ -161,7 +163,7 @@ impl Opt { } /// Get the first short option name, if one exists. - const fn first_short_name(&self) -> Option<&'static str> { + pub(crate) const fn first_short_name(&self) -> Option<&'static str> { const fn predicate(name: &str) -> bool { let mut chars = const_utf8::CharIterator::from(name); if let Some(first) = chars.next() { @@ -174,7 +176,7 @@ impl Opt { false } match self.names { - OptIdentifier::Single(name) => if predicate(&name) { Some(name) } else { None }, + OptIdentifier::Single(name) => if predicate(name) { Some(name) } else { None }, // Can be replaced with `find_map` once iterators are const fn OptIdentifier::Multi(names) => { let mut i = 0; @@ -190,7 +192,7 @@ impl Opt { } /// Get the first applicable short option's flag character, if one exists. - const fn first_short_name_char(&self) -> Option { + pub(crate) const fn first_short_name_char(&self) -> Option { const fn predicate(name: &str) -> Option { let mut chars = const_utf8::CharIterator::from(name); if let Some(first) = chars.next() { @@ -203,7 +205,7 @@ impl Opt { None } match self.names { - OptIdentifier::Single(name) => predicate(&name), + OptIdentifier::Single(name) => predicate(name), // Can be replaced with `find_map` once iterators are const fn. OptIdentifier::Multi(names) => { let mut i = 0; @@ -219,7 +221,7 @@ impl Opt { } /// Search for a matching name in the option, offset allows to skip the first `n = offset` characters in the comparison. - fn match_name(&self, string: &str, offset: usize) -> Option<&'static str> { + pub(crate) fn match_name(&self, string: &str, offset: usize) -> Option<&'static str> { let rhs = &string[offset..]; if rhs.is_empty() { return None; diff --git a/jaarg/src/options.rs b/jaarg/src/options.rs index 8f49b9b..a6559cd 100644 --- a/jaarg/src/options.rs +++ b/jaarg/src/options.rs @@ -3,18 +3,21 @@ * SPDX-License-Identifier: MIT OR Apache-2.0 */ +use crate::{ordered_bitset, Opt}; +use crate::option::OptType; + /// Static structure that contains instructions for parsing command-line arguments. #[derive(Debug, PartialEq)] pub struct Opts { /// List of options - options: &'static[Opt], + pub(crate) options: &'static[Opt], /// String containing single characters that match option prefixes - flag_chars: &'static str, + pub(crate) flag_chars: &'static str, /// A description of what the program does - description: Option<&'static str>, + pub(crate) description: Option<&'static str>, } -type RequiredParamsBitSet = ordered_bitset::OrderedBitSet; +pub(crate) type RequiredParamsBitSet = ordered_bitset::OrderedBitSet; /// The maximum amount of allowed required non-positional options. pub const MAX_REQUIRED_OPTIONS: usize = RequiredParamsBitSet::CAPACITY;