Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 262 - Result and Lossy options for invalid Unicode #265

Merged
merged 3 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 241 additions & 63 deletions src/app/app.rs

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions src/app/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum ClapErrorType {
/// Error occurs when some possible values were set, but clap found unexpected value
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -22,7 +22,7 @@ pub enum ClapErrorType {
/// Error occurs when clap found unexpected flag or option
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -34,7 +34,7 @@ pub enum ClapErrorType {
/// Error occurs when clap found unexpected subcommand
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, SubCommand};
Expand All @@ -50,7 +50,7 @@ pub enum ClapErrorType {
/// Error occurs when option does not allow empty values but some was found
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -70,7 +70,7 @@ pub enum ClapErrorType {
/// Error occurs when argument got more values then were expected
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -83,7 +83,7 @@ pub enum ClapErrorType {
/// Error occurs when argument got less values then were expected
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -96,7 +96,7 @@ pub enum ClapErrorType {
/// Error occurs when clap find two ore more conflicting arguments
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -109,7 +109,7 @@ pub enum ClapErrorType {
/// Error occurs when one or more required arguments missing
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -122,7 +122,7 @@ pub enum ClapErrorType {
/// Error occurs when required subcommand missing
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings, SubCommand};
Expand All @@ -140,7 +140,7 @@ pub enum ClapErrorType {
/// `AppSettings::ArgRequiredElseHelp` was used
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings, SubCommand};
Expand All @@ -157,7 +157,7 @@ pub enum ClapErrorType {
/// Error occurs when clap find argument while is was not expecting any
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App};
Expand All @@ -168,7 +168,7 @@ pub enum ClapErrorType {
/// Error occurs when argument was used multiple times and was not set as multiple.
///
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
Expand All @@ -178,6 +178,24 @@ pub enum ClapErrorType {
/// .get_matches_from_safe(vec!["", "--debug", "--debug"]);
/// ```
UnexpectedMultipleUsage,
/// Error occurs when argument contains invalid unicode characters
///
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
/// # use std::os::unix::ffi::OsStringExt;
/// # use std::ffi::OsString;
/// let result = App::new("myprog")
/// .arg(Arg::with_name("debug")
/// .short("u")
/// .takes_value(true))
/// .get_matches_from_safe(vec![OsString::from_vec(vec![0x20]),
/// OsString::from_vec(vec![0xE9])]);
/// assert!(result.is_err());
/// ```
InvalidUnicode
}

/// Command line argument parser error
Expand Down
16 changes: 8 additions & 8 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub enum AppSettings {
///
/// **NOTE:** This defaults to false (using subcommand does *not* negate requirements)
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, AppSettings};
Expand All @@ -23,7 +23,7 @@ pub enum AppSettings {
///
/// **NOTE:** This defaults to false (subcommands do *not* need to be present)
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, AppSettings};
Expand All @@ -37,7 +37,7 @@ pub enum AppSettings {
///
/// **NOTE:** Subcommands count as arguments
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, AppSettings};
Expand All @@ -52,7 +52,7 @@ pub enum AppSettings {
/// **NOTE:** The version for the current command and this setting must be set **prior** to
/// adding any subcommands
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, SubCommand, AppSettings};
Expand All @@ -72,7 +72,7 @@ pub enum AppSettings {
///
/// **NOTE:** Do not set this value to false, it will have undesired results!
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, SubCommand, AppSettings};
Expand All @@ -90,7 +90,7 @@ pub enum AppSettings {
///
/// **NOTE:** This setting is cosmetic only and does not affect any functionality.
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, SubCommand, AppSettings};
Expand All @@ -112,7 +112,7 @@ pub enum AppSettings {
/// behavior for all subcommands, you must set this on each command (needing this is extremely
/// rare)
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
Expand All @@ -131,7 +131,7 @@ pub enum AppSettings {
/// still be displayed and exit. If this is *not* the desired result, consider using
/// `.arg_required_else_help()`
///
/// # Example
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
Expand Down
Loading