mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
use 2018 edition and minor refactors
This commit is contained in:
parent
92c2b5df3f
commit
dd6c8e08ad
8 changed files with 26 additions and 50 deletions
|
@ -37,6 +37,7 @@ categories = ["command-line-interface"]
|
|||
description = """
|
||||
A simple to use, efficient, and full-featured Command Line Argument Parser
|
||||
"""
|
||||
edition = "2018"
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "clap-rs/clap" }
|
||||
|
|
|
@ -1378,7 +1378,7 @@ impl<'b> App<'b> {
|
|||
T: Into<OsString> + Clone,
|
||||
{
|
||||
debugln!("App::_do_parse;");
|
||||
let mut matcher = ArgMatcher::new();
|
||||
let mut matcher = ArgMatcher::default();
|
||||
|
||||
// If there are global arguments, or settings we need to propgate them down to subcommands
|
||||
// before parsing incase we run into a subcommand
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#[allow(unused_imports)]
|
||||
use std::ops::BitOr;
|
||||
use std::str::FromStr;
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u64 {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Std
|
||||
use std::str::FromStr;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
struct Flags: u32 {
|
||||
const REQUIRED = 1;
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -45,7 +45,6 @@
|
|||
//! // This example demonstrates clap's full 'builder pattern' style of creating arguments which is
|
||||
//! // more verbose, but allows easier editing, and at times more advanced options, or the possibility
|
||||
//! // to generate arguments dynamically.
|
||||
//! extern crate clap;
|
||||
//! use clap::{Arg, App, };
|
||||
//!
|
||||
//! fn main() {
|
||||
|
@ -116,7 +115,6 @@
|
|||
//! //
|
||||
//! // This example demonstrates clap's "usage strings" method of creating arguments
|
||||
//! // which is less verbose
|
||||
//! extern crate clap;
|
||||
//! use clap::{Arg, App, };
|
||||
//!
|
||||
//! fn main() {
|
||||
|
@ -189,7 +187,6 @@
|
|||
//! // This example demonstrates clap's building from YAML style of creating arguments which is far
|
||||
//! // more clean, but takes a very small performance hit compared to the other two methods.
|
||||
//! #[macro_use]
|
||||
//! extern crate clap;
|
||||
//! use clap::App;
|
||||
//!
|
||||
//! fn main() {
|
||||
|
@ -205,8 +202,6 @@
|
|||
//! builder pattern (the first example), but without all the verbosity.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! #[macro_use]
|
||||
//! extern crate clap;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let matches = clap_app!(myapp =>
|
||||
|
@ -285,7 +280,6 @@
|
|||
//! * Add the following to your `src/main.rs`
|
||||
//!
|
||||
//! ```no_run
|
||||
//! extern crate clap;
|
||||
//! use clap::App;
|
||||
//!
|
||||
//! fn main() {
|
||||
|
@ -315,8 +309,6 @@
|
|||
//! git = "https://github.com/kbknapp/clap-rs.git"
|
||||
//! ```
|
||||
//!
|
||||
//! Add `extern crate clap;` to your crate root.
|
||||
//!
|
||||
//! Define a list of valid arguments for your program (see the
|
||||
//! [documentation](https://docs.rs/clap/) or [examples/] directory of this repo)
|
||||
//!
|
||||
|
@ -534,28 +526,6 @@
|
|||
// #![cfg_attr(feature = "lints", allow(doc_markdown))]
|
||||
// #![cfg_attr(feature = "lints", allow(explicit_iter_loop))]
|
||||
|
||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
extern crate ansi_term;
|
||||
#[cfg(feature = "color")]
|
||||
extern crate atty;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[cfg(feature = "derive")]
|
||||
#[cfg_attr(feature = "derive", allow(unused_imports))]
|
||||
#[cfg_attr(feature = "derive", macro_use)]
|
||||
extern crate clap_derive;
|
||||
extern crate indexmap;
|
||||
#[cfg(feature = "suggestions")]
|
||||
extern crate strsim;
|
||||
#[cfg(feature = "wrap_help")]
|
||||
extern crate term_size;
|
||||
extern crate textwrap;
|
||||
extern crate unicode_width;
|
||||
#[cfg(feature = "vec_map")]
|
||||
extern crate vec_map;
|
||||
#[cfg(feature = "yaml")]
|
||||
extern crate yaml_rust;
|
||||
|
||||
pub use crate::build::{App, AppSettings, Arg, ArgGroup, ArgSettings, Propagation};
|
||||
pub use crate::output::fmt::Format;
|
||||
pub use crate::parse::errors::{Error, ErrorKind, Result};
|
||||
|
|
|
@ -99,29 +99,24 @@ impl<'b> MKeyMap<'b> {
|
|||
//TODO ::get_first([KeyA, KeyB])
|
||||
|
||||
pub fn get_mut(&mut self, key: &KeyType) -> Option<&mut Arg<'b>> {
|
||||
for k in &self.keys {
|
||||
if &k.key == key {
|
||||
return self.args.get_mut(k.index);
|
||||
}
|
||||
}
|
||||
None
|
||||
let key = self.keys.iter()
|
||||
.find(|k| k.key == *key);
|
||||
|
||||
match key {
|
||||
Some(k) => self.args.get_mut(k.index),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn is_empty(&self) -> bool { self.keys.is_empty() && self.args.is_empty() }
|
||||
|
||||
pub fn remove_key(&mut self, key: &KeyType) {
|
||||
let mut idx = None;
|
||||
for (i, k) in self.keys.iter().enumerate() {
|
||||
if &k.key == key {
|
||||
idx = Some(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(idx) = idx {
|
||||
self.keys.swap_remove(idx);
|
||||
let idx = self.keys.iter().enumerate().find(|(_,k)| k.key == *key).and_then(|(i, _)| Some(i));
|
||||
if let Some(id) = idx {
|
||||
self.keys.swap_remove(id);
|
||||
}
|
||||
}
|
||||
//TODO ::remove_keys([KeyA, KeyB])
|
||||
|
||||
pub fn insert_key_by_name(&mut self, key: KeyType, name: &str) {
|
||||
let index = self.find_by_name(name);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
// Third Party
|
||||
use indexmap;
|
||||
|
@ -20,8 +21,14 @@ impl Default for ArgMatcher {
|
|||
fn default() -> Self { ArgMatcher(ArgMatches::default()) }
|
||||
}
|
||||
|
||||
impl Deref for ArgMatcher {
|
||||
type Target = ArgMatches;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ArgMatcher {
|
||||
pub fn new() -> Self { ArgMatcher::default() }
|
||||
|
||||
pub fn into_inner(self) -> ArgMatches { self.0 }
|
||||
|
||||
|
|
|
@ -623,7 +623,7 @@ where
|
|||
};
|
||||
|
||||
// Collect the external subcommand args
|
||||
let mut sc_m = ArgMatcher::new();
|
||||
let mut sc_m = ArgMatcher::default();
|
||||
while let Some(v) = it.next() {
|
||||
let a = v.into();
|
||||
if a.to_str().is_none() && !self.is_set(AS::StrictUtf8) {
|
||||
|
@ -888,7 +888,7 @@ where
|
|||
self.app._propagate(Propagation::To(id));
|
||||
}
|
||||
if let Some(sc) = subcommands_mut!(self.app).find(|s| s.name == sc_name) {
|
||||
let mut sc_matcher = ArgMatcher::new();
|
||||
let mut sc_matcher = ArgMatcher::default();
|
||||
// bin_name should be parent's bin_name + [<reqs>] + the sc's name separated by
|
||||
// a space
|
||||
sc.usage = Some(format!(
|
||||
|
|
Loading…
Reference in a new issue