argparse: Use a named constant for RETURN_IN_ORDER returns

The RETURN_IN_ORDER argparse mode (enabled via leading '-') causes non-options
(i.e. positionals) to be returned intermixed with options in the original order,
instead of being permuted to the end. Such positionals are identified via the
option sentinel of char code 1. Use a real named constant for this return,
rather than weird stuff like '\u{1}'
This commit is contained in:
ridiculousfish 2023-07-15 11:35:13 -07:00
parent bfd97adbda
commit ecfabf4db8
2 changed files with 6 additions and 3 deletions

View file

@ -12,7 +12,7 @@ use crate::ffi::Repin;
use crate::wchar::{wstr, WString, L};
use crate::wchar_ext::WExt;
use crate::wcstringutil::split_string;
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t, NONOPTION_CHAR_CODE};
use crate::wutil::{fish_iswalnum, fish_wcstol, wgettext_fmt};
use libc::c_int;
@ -832,7 +832,7 @@ fn argparse_parse_flags<'args>(
STATUS_CMD_OK
}
}
'\u{1}' => {
NONOPTION_CHAR_CODE => {
// A non-option argument.
// We use `-` as the first option-string-char to disable GNU getopt's reordering,
// otherwise we'd get ignored options first and normal arguments later.

View file

@ -54,6 +54,9 @@ enum Ordering {
RETURN_IN_ORDER,
}
/// The special character code, enabled via RETURN_IN_ORDER, indicating a non-option argument.
pub const NONOPTION_CHAR_CODE: char = '\x01';
impl Default for Ordering {
fn default() -> Self {
Ordering::PERMUTE
@ -323,7 +326,7 @@ impl<'opts, 'args, 'argarray> wgetopter_t<'opts, 'args, 'argarray> {
}
self.woptarg = Some(self.argv[self.woptind]);
self.woptind += 1;
return Some(char::from(1));
return Some(NONOPTION_CHAR_CODE);
}
// We have found another option-ARGV-element. Skip the initial punctuation.