2
0
Fork 0
mirror of https://github.com/clap-rs/clap synced 2024-12-14 14:52:33 +00:00
1873: Bugfix r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
This commit is contained in:
bors[bot] 2020-04-27 19:18:36 +00:00 committed by GitHub
commit 638880271a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 178 additions and 130 deletions

View file

@ -5,27 +5,29 @@ mod tests;
pub use self::settings::AppSettings;
// Std
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::io::{self, BufRead, Write};
use std::ops::Index;
use std::path::Path;
use std::process;
use std::{
collections::HashMap,
env,
ffi::OsString,
fmt,
io::{self, BufRead, Write},
ops::Index,
path::Path,
};
// Third Party
#[cfg(feature = "yaml")]
use yaml_rust::Yaml;
// Internal
use crate::build::{app::settings::AppFlags, Arg, ArgGroup, ArgSettings};
use crate::mkeymap::MKeyMap;
use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
use crate::parse::errors::Result as ClapResult;
use crate::parse::{ArgMatcher, ArgMatches, Input, Parser};
use crate::util::{termcolor::ColorChoice, Id, Key};
use crate::INTERNAL_ERROR_MSG;
use crate::{
build::{app::settings::AppFlags, Arg, ArgGroup, ArgSettings},
mkeymap::MKeyMap,
output::{fmt::Colorizer, Help, HelpWriter, Usage},
parse::{ArgMatcher, ArgMatches, Input, Parser},
util::{safe_exit, termcolor::ColorChoice, Id, Key},
Result as ClapResult, INTERNAL_ERROR_MSG,
};
// FIXME (@CreepySkeleton): some of these variants are never constructed
#[derive(Clone, Debug, PartialEq, Eq)]
@ -1299,7 +1301,7 @@ impl<'b> App<'b> {
}
drop(e);
process::exit(2);
safe_exit(2);
}
e.exit()
@ -1377,7 +1379,7 @@ impl<'b> App<'b> {
drop(self);
drop(e);
process::exit(2);
safe_exit(2);
}
drop(self);
@ -1912,7 +1914,7 @@ impl<'b> App<'b> {
};
if let Some(bn) = self.bin_name.as_ref() {
if bn.contains(' ') {
// Incase we're dealing with subcommands i.e. git mv is translated to git-mv
// In case we're dealing with subcommands i.e. git mv is translated to git-mv
write!(w, "{} {}", bn.replace(" ", "-"), ver)
} else {
write!(w, "{} {}", &self.name[..], ver)

View file

@ -1,8 +1,8 @@
// Std
use std::{ops::BitOr, str::FromStr};
// Third party
use bitflags::bitflags;
#[allow(unused_imports)]
use std::ops::BitOr;
use std::str::FromStr;
bitflags! {
struct Flags: u64 {

View file

@ -5,21 +5,25 @@ mod tests;
pub use self::settings::ArgSettings;
// Std
use std::borrow::Cow;
use std::cmp::{Ord, Ordering};
use std::env;
use std::ffi::{OsStr, OsString};
use std::fmt::{self, Display, Formatter};
use std::rc::Rc;
use std::str;
use std::{
borrow::Cow,
cmp::{Ord, Ordering},
env,
ffi::{OsStr, OsString},
fmt::{self, Display, Formatter},
rc::Rc,
str,
};
// Third Party
use crate::util::VecMap;
// Internal
use crate::build::{arg::settings::ArgFlags, usage_parser::UsageParser};
use crate::util::{Id, Key};
use crate::INTERNAL_ERROR_MSG;
use crate::{
build::{arg::settings::ArgFlags, usage_parser::UsageParser},
util::VecMap,
util::{Id, Key},
INTERNAL_ERROR_MSG,
};
type Validator = Rc<dyn Fn(String) -> Result<(), String>>;
type ValidatorOs = Rc<dyn Fn(&OsStr) -> Result<(), String>>;

View file

@ -1,6 +1,7 @@
// Std
use std::str::FromStr;
// Third party
use bitflags::bitflags;
bitflags! {

View file

@ -1,5 +1,4 @@
// Std
use std::fmt::{Debug, Formatter, Result};
// Internal

View file

@ -7,6 +7,8 @@ pub mod arg;
mod arg_group;
mod usage_parser;
pub use self::app::{App, AppSettings};
pub use self::arg::{Arg, ArgSettings};
pub use self::arg_group::ArgGroup;
pub use self::{
app::{App, AppSettings},
arg::{Arg, ArgSettings},
arg_group::ArgGroup,
};

View file

@ -1,7 +1,9 @@
// Internal
use crate::build::{Arg, ArgSettings};
use crate::util::VecMap;
use crate::INTERNAL_ERROR_MSG;
use crate::{
build::{Arg, ArgSettings},
util::VecMap,
INTERNAL_ERROR_MSG,
};
#[derive(PartialEq, Debug)]
enum UsageToken {

View file

@ -1,6 +1,7 @@
//! This module contains traits that are usable with `#[derive(...)].`
use crate::{App, ArgMatches, Error};
use std::ffi::OsString;
/// This trait is just a convenience on top of FromArgMatches + IntoApp

View file

@ -446,10 +446,12 @@
#[cfg(not(feature = "std"))]
compile_error!("`std` feature is currently required to build `clap`");
pub use crate::build::{App, AppSettings, Arg, ArgGroup, ArgSettings};
pub use crate::derive::{ArgEnum, Clap, FromArgMatches, IntoApp, Subcommand};
pub use crate::parse::errors::{Error, ErrorKind, Result};
pub use crate::parse::{ArgMatches, OsValues, SubCommand, Values};
pub use crate::{
build::{App, AppSettings, Arg, ArgGroup, ArgSettings},
derive::{ArgEnum, Clap, FromArgMatches, IntoApp, Subcommand},
parse::errors::{Error, ErrorKind, Result},
parse::{ArgMatches, OsValues, SubCommand, Values},
};
#[cfg(feature = "yaml")]
pub use yaml_rust::YamlLoader;

View file

@ -1,8 +1,9 @@
use crate::build::Arg;
use crate::util::Id;
use crate::INTERNAL_ERROR_MSG;
use std::ffi::{OsStr, OsString};
use std::ops::Index;
use crate::{build::Arg, util::Id, INTERNAL_ERROR_MSG};
use std::{
ffi::{OsStr, OsString},
ops::Index,
};
#[derive(PartialEq, Debug, Clone)]
pub(crate) struct Key {

View file

@ -2,8 +2,10 @@ use crate::util::termcolor::{Buffer, BufferWriter, ColorChoice};
#[cfg(feature = "color")]
use crate::util::termcolor::{Color, ColorSpec, WriteColor};
use std::fmt::{self, Debug, Formatter};
use std::io::{Result, Write};
use std::{
fmt::{self, Debug, Formatter},
io::{Result, Write},
};
#[cfg(feature = "color")]
fn is_a_tty(stderr: bool) -> bool {

View file

@ -1,18 +1,23 @@
// Std
use std::borrow::Cow;
use std::cmp;
use std::collections::BTreeMap;
use std::io::{self, Cursor, Read, Write};
use std::usize;
use std::{
borrow::Cow,
cmp,
collections::BTreeMap,
io::{self, Cursor, Read, Write},
usize,
};
// Internal
use crate::build::{App, AppSettings, Arg, ArgSettings};
use crate::output::{fmt::Colorizer, Usage};
use crate::parse::errors::{Error, Result as ClapResult};
use crate::parse::Parser;
use crate::util::VecMap;
use crate::INTERNAL_ERROR_MSG;
use crate::{
build::{App, AppSettings, Arg, ArgSettings},
output::{fmt::Colorizer, Usage},
parse::errors::{Error, Result as ClapResult},
parse::Parser,
util::VecMap,
INTERNAL_ERROR_MSG,
};
// Third party
use unicode_width::UnicodeWidthStr;
#[cfg(not(feature = "wrap_help"))]

View file

@ -1,12 +1,14 @@
// std
use crate::util::Id;
use std::collections::{BTreeMap, VecDeque};
// Internal
use crate::build::AppSettings as AS;
use crate::build::{Arg, ArgSettings};
use crate::parse::{ArgMatcher, Parser};
use crate::INTERNAL_ERROR_MSG;
use crate::{
build::AppSettings as AS,
build::{Arg, ArgSettings},
parse::{ArgMatcher, Parser},
util::Id,
INTERNAL_ERROR_MSG,
};
pub(crate) struct Usage<'b, 'c, 'z>
where

View file

@ -1,13 +1,12 @@
// Std
use std::collections::HashMap;
use std::ffi::OsString;
use std::mem;
use std::ops::Deref;
use std::{collections::HashMap, ffi::OsString, mem, ops::Deref};
// Internal
use crate::build::{Arg, ArgSettings};
use crate::parse::{ArgMatches, MatchedArg, SubCommand, ValueType};
use crate::util::Id;
use crate::{
build::{Arg, ArgSettings},
parse::{ArgMatches, MatchedArg, SubCommand, ValueType},
util::Id,
};
#[derive(Debug)]
pub(crate) struct ArgMatcher(pub(crate) ArgMatches);

View file

@ -1,16 +1,19 @@
// Std
use std::collections::VecDeque;
use std::convert::From;
use std::fmt::{self, Debug, Display, Formatter};
use std::io;
use std::process;
use std::result::Result as StdResult;
use std::{
collections::VecDeque,
convert::From,
fmt::{self, Debug, Display, Formatter},
io,
result::Result as StdResult,
};
// Internal
use crate::build::{Arg, ArgGroup};
use crate::output::fmt::Colorizer;
use crate::parse::features::suggestions;
use crate::util::termcolor::ColorChoice;
use crate::{
build::{Arg, ArgGroup},
output::fmt::Colorizer,
parse::features::suggestions,
util::{safe_exit, termcolor::ColorChoice},
};
/// Short hand for [`Result`] type
///
@ -430,11 +433,11 @@ impl Error {
pub fn exit(&self) -> ! {
if self.use_stderr() {
self.message.print().expect("Error writing Error to stderr");
process::exit(1);
safe_exit(1);
}
self.message.print().expect("Error writing Error to stdout");
process::exit(0);
safe_exit(0)
}
#[allow(unused)] // requested by @pksunkara

View file

@ -1,18 +1,22 @@
// Std
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::fmt::{Debug, Display};
use std::iter::{Cloned, Map};
use std::slice::Iter;
use std::str::FromStr;
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
fmt::{Debug, Display},
iter::{Cloned, Map},
slice::Iter,
str::FromStr,
};
// Third Party
use indexmap::IndexMap;
// Internal
use crate::parse::{MatchedArg, SubCommand};
use crate::util::{Id, Key};
use crate::{Error, INVALID_UTF8};
use crate::{
parse::{MatchedArg, SubCommand},
util::{Id, Key},
{Error, INVALID_UTF8},
};
/// Used to get information about the arguments that were supplied to the program at runtime by
/// the user. New instances of this struct are obtained by using the [`App::get_matches`] family of

View file

@ -1,6 +1,5 @@
// Internal
use crate::util::Id;
use crate::ArgMatches;
use crate::{util::Id, ArgMatches};
/// The abstract representation of a command line subcommand.
///

View file

@ -1,23 +1,26 @@
// Std
use std::cell::Cell;
use std::ffi::{OsStr, OsString};
use std::io::Write;
use std::{
cell::Cell,
ffi::{OsStr, OsString},
io::Write,
};
// Internal
use crate::build::app::Propagation;
use crate::build::AppSettings as AS;
use crate::build::{App, Arg, ArgSettings};
use crate::mkeymap::KeyType;
use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
use crate::parse::errors::Error as ClapError;
use crate::parse::errors::ErrorKind;
use crate::parse::errors::Result as ClapResult;
use crate::parse::features::suggestions;
use crate::parse::{ArgMatcher, SubCommand};
use crate::parse::{Validator, ValueType};
use crate::util::{termcolor::ColorChoice, ArgStr, ChildGraph, Id};
use crate::INTERNAL_ERROR_MSG;
use crate::INVALID_UTF8;
use crate::{
build::app::Propagation,
build::AppSettings as AS,
build::{App, Arg, ArgSettings},
mkeymap::KeyType,
output::{fmt::Colorizer, Help, HelpWriter, Usage},
parse::errors::Error as ClapError,
parse::errors::ErrorKind,
parse::errors::Result as ClapResult,
parse::features::suggestions,
parse::{ArgMatcher, SubCommand},
parse::{Validator, ValueType},
util::{termcolor::ColorChoice, ArgStr, ChildGraph, Id},
INTERNAL_ERROR_MSG, INVALID_UTF8,
};
#[derive(Debug, PartialEq, Clone)]
pub(crate) enum ParseResult {

View file

@ -1,13 +1,14 @@
// Internal
use crate::build::app::AppSettings as AS;
use crate::build::{Arg, ArgSettings};
use crate::output::Usage;
use crate::parse::errors::Result as ClapResult;
use crate::parse::errors::{Error, ErrorKind};
use crate::parse::{ArgMatcher, MatchedArg, ParseResult, Parser, ValueType};
use crate::util::{ChildGraph, Id};
use crate::INTERNAL_ERROR_MSG;
use crate::INVALID_UTF8;
use crate::{
build::{AppSettings as AS, Arg, ArgSettings},
output::Usage,
parse::{
errors::{Error, ErrorKind, Result as ClapResult},
ArgMatcher, MatchedArg, ParseResult, Parser, ValueType,
},
util::{ChildGraph, Id},
INTERNAL_ERROR_MSG, INVALID_UTF8,
};
pub(crate) struct Validator<'b, 'c, 'z>
where

View file

@ -1,6 +1,8 @@
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::str;
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
str,
};
use os_str_bytes::{OsStrBytes, OsStringBytes};

View file

@ -1,5 +1,7 @@
use std::fmt::Display;
use std::hash::{Hash, Hasher};
use std::{
fmt::Display,
hash::{Hash, Hasher},
};
const MAGIC_INIT: u64 = 0x811C_9DC5;

View file

@ -1,7 +1,10 @@
use crate::util::fnv::Key;
use std::fmt::{Debug, Formatter, Result};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::{
fmt::{Debug, Formatter, Result},
hash::{Hash, Hasher},
ops::Deref,
};
#[derive(Clone, Eq, Default)]
#[cfg_attr(not(debug_assertions), derive(Copy), repr(transparent))]

View file

@ -15,3 +15,12 @@ pub(crate) use termcolor;
#[cfg(not(feature = "color"))]
pub(crate) mod termcolor;
pub(crate) fn safe_exit(code: i32) -> ! {
use std::io::Write;
let _ = std::io::stdout().lock().flush();
let _ = std::io::stderr().lock().flush();
std::process::exit(code)
}