mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
refactor(lex): Track replacements as str
The lexer will soon return `RawOsStr` and it'll cost to turn that into an `OsStr`. However, it caches a `str`, so let's just use that.
This commit is contained in:
parent
f66d8abebd
commit
c58928b6bd
2 changed files with 5 additions and 5 deletions
|
@ -3,7 +3,6 @@
|
|||
// Std
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::OsString;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
@ -101,7 +100,7 @@ pub struct App<'help> {
|
|||
g_settings: AppFlags,
|
||||
args: MKeyMap<'help>,
|
||||
subcommands: Vec<App<'help>>,
|
||||
replacers: HashMap<&'help OsStr, &'help [&'help str]>,
|
||||
replacers: HashMap<&'help str, &'help [&'help str]>,
|
||||
groups: Vec<ArgGroup<'help>>,
|
||||
current_help_heading: Option<&'help str>,
|
||||
current_disp_ord: Option<usize>,
|
||||
|
@ -1945,7 +1944,7 @@ impl<'help> App<'help> {
|
|||
#[cfg(feature = "unstable-replace")]
|
||||
#[must_use]
|
||||
pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self {
|
||||
self.replacers.insert(OsStr::new(name), target);
|
||||
self.replacers.insert(name, target);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -3933,7 +3932,7 @@ impl<'help> App<'help> {
|
|||
self.max_w
|
||||
}
|
||||
|
||||
pub(crate) fn get_replacement(&self, key: &OsStr) -> Option<&[&str]> {
|
||||
pub(crate) fn get_replacement(&self, key: &str) -> Option<&[&str]> {
|
||||
self.replacers.get(key).copied()
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,8 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
|
|||
|
||||
while let Some(arg_os) = raw_args.next(&mut args_cursor) {
|
||||
// Recover the replaced items if any.
|
||||
if let Some(replaced_items) = self.cmd.get_replacement(arg_os) {
|
||||
if let Some(replaced_items) = arg_os.to_str().and_then(|a| self.cmd.get_replacement(a))
|
||||
{
|
||||
debug!(
|
||||
"Parser::get_matches_with: found replacer: {:?}, target: {:?}",
|
||||
arg_os, replaced_items
|
||||
|
|
Loading…
Reference in a new issue