This commit is contained in:
Alena Yuryeva 2018-07-26 20:15:47 +05:00 committed by Kevin K
parent 7e5a6935b9
commit f230cfedc3
No known key found for this signature in database
GPG key ID: 2E39D46AABC94DDD
8 changed files with 52 additions and 74 deletions

View file

@ -1,5 +1,6 @@
// Std
use std::io::Write;
use std::ffi::OsStr;
// Internal
use build::{App, Arg};
@ -131,7 +132,7 @@ complete -F _{name} -o bashdefault -o default {name}
p = &find_subcmd!(p, sc).unwrap();
}
let mut opts = String::new();
for o in opts!(p) {
for (_, o) in opts!(p) {
if let Some(l) = o.long {
opts = format!(
"{}
@ -180,7 +181,8 @@ complete -F _{name} -o bashdefault -o default {name}
"{shorts} {longs} {pos} {subcmds}",
shorts = shorts!(p).fold(String::new(), |acc, s| format!("{} -{}", acc, s)),
// Handles aliases too
longs = longs!(p).fold(String::new(), |acc, l| format!("{} --{}", acc, l)),
// error-handling?
longs = longs!(p).fold(String::new(), |acc, l| format!("{} --{}", acc, l.to_str().unwrap()),
pos = positionals!(p).fold(String::new(), |acc, p| format!("{} {}", acc, p)),
// Handles aliases too
subcmds = sc_names!(p).fold(String::new(), |acc, s| format!("{} {}", acc, s))

View file

@ -80,7 +80,7 @@ where
let mut completions = String::new();
let preamble = String::from("\n cand ");
for option in opts!(p) {
for (_, option) in opts!(p) {
if let Some(data) = option.short {
let tooltip = get_tooltip(option.help, data);
completions.push_str(&preamble);
@ -93,7 +93,7 @@ where
}
}
for flag in flags!(p) {
for (_, flag) in flags!(p) {
if let Some(data) = flag.short {
let tooltip = get_tooltip(flag.help, data);
completions.push_str(&preamble);

View file

@ -44,7 +44,7 @@ fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, subcommand: &str, buff
basic_template.push_str(format!("\"__fish_seen_subcommand_from {}\"", subcommand).as_str());
}
for option in opts!(comp_gen.0) {
for (_, option) in opts!(comp_gen.0) {
let mut template = basic_template.clone();
if let Some(data) = option.short {
template.push_str(format!(" -s {}", data).as_str());
@ -62,7 +62,7 @@ fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, subcommand: &str, buff
buffer.push_str("\n");
}
for flag in flags!(comp_gen.0) {
for (_, flag) in flags!(comp_gen.0) {
let mut template = basic_template.clone();
if let Some(data) = flag.short {
template.push_str(format!(" -s {}", data).as_str());

View file

@ -79,7 +79,7 @@ fn generate_inner<'a, 'b, 'p>(
let mut completions = String::new();
let preamble = String::from("\n [CompletionResult]::new(");
for option in opts!(p) {
for (_, option) in opts!(p) {
if let Some(data) = option.short {
let tooltip = get_tooltip(option.help, data);
completions.push_str(&preamble);
@ -102,7 +102,7 @@ fn generate_inner<'a, 'b, 'p>(
}
}
for flag in flags!(p) {
for (_, flag) in flags!(p) {
if let Some(data) = flag.short {
let tooltip = get_tooltip(flag.help, data);
completions.push_str(&preamble);

View file

@ -334,7 +334,7 @@ fn escape_value(string: &str) -> String {
fn write_opts_of(p: &App) -> String {
debugln!("write_opts_of;");
let mut ret = vec![];
for o in opts!(p) {
for (_, o) in opts!(p) {
debugln!("write_opts_of:iter: o={}", o.name);
let help = o.help.map_or(String::new(), escape_help);
let mut conflicts = get_zsh_arg_conflicts!(p, o, INTERNAL_ERROR_MSG);
@ -399,7 +399,7 @@ fn write_opts_of(p: &App) -> String {
fn write_flags_of(p: &App) -> String {
debugln!("write_flags_of;");
let mut ret = vec![];
for f in flags!(p) {
for (_, f) in flags!(p) {
debugln!("write_flags_of:iter: f={}", f.name);
let help = f.help.map_or(String::new(), escape_help);
let mut conflicts = get_zsh_arg_conflicts!(p, f, INTERNAL_ERROR_MSG);

View file

@ -517,11 +517,7 @@
//! [license]: https://raw.githubusercontent.com/kbknapp/clap-rs/master/LICENSE-MIT
#![crate_type = "lib"]
<<<<<<< HEAD
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-alpha.1")]
=======
#![doc(html_root_url = "https://docs.rs/clap/3.0.0-alpha1")]
>>>>>>> WIP. Big reformat
#![deny(
missing_docs,
missing_debug_implementations,
@ -585,18 +581,14 @@ use std::result::Result as StdResult;
#[macro_use]
mod macros;
<<<<<<< HEAD
<<<<<<< HEAD
mod build;
=======
mod mkeymap;
>>>>>>> WIP changing macros into MKeyMap calls
mod completions;
=======
mod build;
mod completions;
mod mkeymap;
>>>>>>> WIP. Big reformat
mod output;
mod parse;
mod util;

View file

@ -9,7 +9,7 @@ use std::hash::{Hash, Hasher};
use std::slice;
// ! rustdoc
#[derive(Default, PartialEq, Debug)]
#[derive(Default, PartialEq, Debug, Clone)]
pub struct MKeyMap<'a, 'b>
where
'a: 'b,

View file

@ -246,11 +246,7 @@ where
let mut found = false;
let mut foundx2 = false;
for p in self
.positionals
.values()
.rev()
.map(|p_name| self.app.find(p_name).expect(INTERNAL_ERROR_MSG))
for p in positionals!(self.app)
{
if foundx2 && !p.is_set(ArgSettings::Required) {
assert!(
@ -282,11 +278,7 @@ where
// Check that if a required positional argument is found, all positions with a lower
// index are also required
let mut found = false;
for p in self
.positionals
.values()
.rev()
.map(|p_name| self.app.find(p_name).expect(INTERNAL_ERROR_MSG))
for p in positionals!(self.app)
{
if found {
assert!(
@ -337,7 +329,7 @@ where
for (i, a) in self.app.args.values_mut().enumerate() {
if let Some(index) = a.index {
self.app.args.insert_key(KeyType::Position(index), i);
self.app.args.insert_key(KeyType::Position(index as usize), i);
} else {
if let Some(c) = a.short {
self.app.args.insert_key(KeyType::Short(c), i);
@ -393,7 +385,7 @@ where
.app
.args
.keys()
.filter(|x| if let Position(_) = x { true } else { false })
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
.count())
}) && self.positionals.values().last().map_or(false, |p_name| {
!self
@ -494,7 +486,8 @@ where
}
if starts_new_arg {
self.seen.extend(self.cache);
// ! add values to seen somewhere?
//self.seen.extend(self.cache);
if arg_os.starts_with(b"--") {
needs_val_of = self.parse_long_arg(matcher, &arg_os)?;
debugln!(
@ -566,9 +559,21 @@ where
}
let low_index_mults = self.is_set(AS::LowIndexMultiplePositional)
&& pos_counter == (self.positionals.len() - 1);
&& pos_counter == (
//TODO make a macro for that
self
.app
.args
.keys()
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
.count() - 1);
let missing_pos = self.is_set(AS::AllowMissingPositional)
&& (pos_counter == (self.positionals.len() - 1)
&& (pos_counter == (self
.app
.args
.keys()
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
.count() - 1)
&& !self.is_set(AS::TrailingValues));
debugln!(
"Parser::get_matches_with: Positional counter...{}",
@ -610,7 +615,12 @@ where
// Came to -- and one postional has .last(true) set, so we go immediately
// to the last (highest index) positional
debugln!("Parser::get_matches_with: .last(true) and --, setting last pos");
pos_counter = self.positionals.len();
pos_counter = self
.app
.args
.keys()
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
.count();
}
if let Some(p) = positionals!(self.app).find(|p| p.index == Some(pos_counter as u64)) {
if p.is_set(ArgSettings::Last) && !self.is_set(AS::TrailingValues) {
@ -622,13 +632,15 @@ where
));
}
if !self.is_set(AS::TrailingValues)
&& (self.is_set(AS::TrailingVarArg) && pos_counter == self.positionals.len())
&& (self.is_set(AS::TrailingVarArg) && pos_counter == self
.app
.args
.keys()
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
.count())
{
self.app.settings.set(AS::TrailingValues);
}
if self.cache.map_or(true, |name| name != p.name) {
self.cache = Some(p.name);
}
let _ = self.add_val_to_arg(p, &arg_os, matcher)?;
matcher.inc_occurrence_of(p.name);
@ -714,7 +726,7 @@ where
}
// Make sure we get the last one too
self.seen.extend(self.cache);
//self.seen.extend(self.cache);
if let Some(ref pos_sc_name) = subcmd_name {
let sc_name = {
@ -830,7 +842,7 @@ where
.setting(ArgSettings::MultipleValues)
.help("The subcommand whose help message to display");
pb._build();
parser.positionals.insert(1, pb.name);
//parser.positionals.insert(1, pb.name);
parser.app.settings = parser.app.settings | self.app.g_settings;
parser.app.g_settings = self.app.g_settings;
}
@ -1130,10 +1142,6 @@ where
// Default to "we're expecting a value later"
let ret = self.parse_opt(val, opt, false, matcher)?;
if self.cache.map_or(true, |name| name != opt.name) {
self.cache = Some(opt.name);
}
return Ok(ret);
} else if let Some(flag) = self.app.args.get(KeyType::Short(c)) {
debugln!("Parser::parse_short_arg:iter:{}: Found valid flag", c);
@ -1141,12 +1149,6 @@ where
// Only flags can be help or version
self.check_for_help_and_version_char(c)?;
ret = self.parse_flag(flag, matcher)?;
// Handle conflicts, requirements, overrides, etc.
// Must be called here due to mutablilty
if self.cache.map_or(true, |name| name != flag.name) {
self.cache = Some(flag.name);
}
} else {
let arg = format!("-{}", c);
return Err(ClapError::unknown_argument(
@ -1406,9 +1408,6 @@ where
);
$_self.add_val_to_arg($a, OsStr::new(val), $m)?;
if $_self.cache.map_or(true, |name| name != $a.name) {
$_self.cache = Some($a.name);
}
} else if $m.get($a.name).is_some() {
debugln!(
"Parser::add_defaults:iter:{}: has user defined vals",
@ -1418,10 +1417,6 @@ where
debugln!("Parser::add_defaults:iter:{}: wasn't used", $a.name);
$_self.add_val_to_arg($a, OsStr::new(val), $m)?;
if $_self.cache.map_or(true, |name| name != $a.name) {
$_self.cache = Some($a.name);
}
}
} else {
debugln!(
@ -1447,9 +1442,6 @@ where
};
if add {
$_self.add_val_to_arg($a, OsStr::new(default), $m)?;
if $_self.cache.map_or(true, |name| name != $a.name) {
$_self.cache = Some($a.name);
}
done = true;
break;
}
@ -1466,7 +1458,7 @@ where
};
}
for o in opts!(self.app) {
for (k, o) in opts!(self.app) {
debug!("Parser::add_defaults:iter:{}:", o.name);
add_val!(self, o, matcher);
}
@ -1488,18 +1480,10 @@ where
{
if let Some(ref val) = val.1 {
self.add_val_to_arg(a, OsStr::new(val), matcher)?;
if self.cache.map_or(true, |name| name != a.name) {
self.cache = Some(a.name);
}
}
} else {
if let Some(ref val) = val.1 {
self.add_val_to_arg(a, OsStr::new(val), matcher)?;
if self.cache.map_or(true, |name| name != a.name) {
self.cache = Some(a.name);
}
}
}
}
@ -1526,7 +1510,7 @@ where
matcher.inc_occurrence_of(&*grp);
}
matcher.insert(&*opt.name);
} else if let Some(flg) = self.app.args.get(KeyType::Long(name)) {
} else if let Some(flg) = self.app.args.get(KeyType::Long(&OsStr::new(name))) {
self.groups_for_arg(&*flg.name)
.and_then(|grps| Some(matcher.inc_occurrences_of(&*grps)));
matcher.insert(&*flg.name);