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

Update clap requirement from 3.0 to 4.0 #230

Merged
merged 4 commits into from
Oct 3, 2022
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
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ All user visible changes to `cucumber` crate will be documented in this file. Th



## [0.15.0] · 2022-10-??
[0.15.0]: /../../tree/v0.15.0

[Diff](/../../compare/v0.14.2...v0.15.0) | [Milestone](/../../milestone/15)

### BC Breaks

- Upgraded [`clap`] crate to 4.0 version. ([#230])

[#230]: /../../pull/230




## [0.14.2] · 2022-09-19
[0.14.2]: /../../tree/v0.14.2

Expand Down Expand Up @@ -224,7 +238,7 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
- Bump up [MSRV] to 1.57 for better error reporting in `const` assertions. ([cef3d480])
- Switch to [`gherkin`] crate instead of [`gherkin_rust`]. ([e2a41ab0])
- Renamed `@allow_skipped` built-in tag to `@allow.skipped`. ([#181])
- Switched CLI to `clap` from `structopt`. ([#188], [#155])
- Switched CLI to [`clap`] from `structopt`. ([#188], [#155])
- Reworked `verbose` CLI option of `writer::Basic`: ([#193], [#192])
- Removed long form.
- Made `-v` default behavior (no additional output).
Expand Down Expand Up @@ -500,6 +514,7 @@ All user visible changes to `cucumber` crate will be documented in this file. Th



[`clap`]: https://docs.rs/clap
[`gherkin`]: https://docs.rs/gherkin
[`gherkin_rust`]: https://docs.rs/gherkin_rust

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ timestamps = []
anyhow = { version = "1.0.58", optional = true }
async-trait = "0.1.43"
atty = "0.2.14"
clap = { version = "3.0", features = ["derive"] }
clap = { version = "4.0.6", features = ["derive", "wrap_help"] }
console = "0.15"
derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "into"], default_features = false }
drain_filter_polyfill = "0.1.2"
Expand Down
119 changes: 57 additions & 62 deletions book/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,60 @@ cargo test --test <test-name> -- --help

Default output is:
```
cucumber
Run the tests, pet a dog!

USAGE:
cucumber [OPTIONS]

OPTIONS:
-c, --concurrency <int>
Number of scenarios to run concurrently. If not specified, uses the value configured in
tests runner, or 64 by default

--color <auto|always|never>
Coloring policy for a console output

[default: auto]

--fail-fast
Run tests until the first failure

-h, --help
Print help information

-i, --input <glob>
Glob pattern to look for feature files with. By default, looks for `*.feature`s in the
path configured tests runner

-n, --name <regex>
Regex to filter scenarios by their name

[aliases: scenario-name]

--retry <int>
Number of times a scenario will be retried in case of a failure

--retry-after <duration>
Delay between each scenario retry attempt.

Duration is represented in a human-readable format like `12min5s`.
Supported suffixes:
- `nsec`, `ns` — nanoseconds.
- `usec`, `us` — microseconds.
- `msec`, `ms` — milliseconds.
- `seconds`, `second`, `sec`, `s` - seconds.
- `minutes`, `minute`, `min`, `m` - minutes.

--retry-tag-filter <tagexpr>
Tag expression to filter retried scenarios

-t, --tags <tagexpr>
Tag expression to filter scenarios by.

Note: Tags from Feature, Rule and Scenario are merged together on filtering, so be
careful about conflicting tags on different levels.

-v
Verbosity of an output.

`-v` is default verbosity, `-vv` additionally outputs world on failed steps, `-vvv`
additionally outputs step's doc string (if present).
Usage: cucumber [OPTIONS]

Options:
-n, --name <regex>
Regex to filter scenarios by their name

[aliases: scenario-name]

-t, --tags <tagexpr>
Tag expression to filter scenarios by.

Note: Tags from Feature, Rule and Scenario are merged together on filtering, so be careful about conflicting tags on different levels.

-i, --input <glob>
Glob pattern to look for feature files with. By default, looks for `*.feature`s in the path configured tests runner

-c, --concurrency <int>
Number of scenarios to run concurrently. If not specified, uses the value configured in tests runner, or 64 by default

--fail-fast
Run tests until the first failure

--retry <int>
Number of times a scenario will be retried in case of a failure

--retry-after <duration>
Delay between each scenario retry attempt.

Duration is represented in a human-readable format like `12min5s`.
Supported suffixes:
- `nsec`, `ns` — nanoseconds.
- `usec`, `us` — microseconds.
- `msec`, `ms` — milliseconds.
- `seconds`, `second`, `sec`, `s` - seconds.
- `minutes`, `minute`, `min`, `m` - minutes.

--retry-tag-filter <tagexpr>
Tag expression to filter retried scenarios

-v...
Verbosity of an output.

`-v` is default verbosity, `-vv` additionally outputs world on failed steps, `-vvv` additionally outputs step's doc string (if present).

--color <auto|always|never>
Coloring policy for a console output

[default: auto]

-h, --help
Print help information (use `-h` for a summary)

```

![record](rec/cli.gif)
Expand Down Expand Up @@ -129,9 +124,9 @@ CLI may be extended even more with arbitrary options, if required. In such case
#[derive(cli::Args)] // re-export of `clap::Args`
struct CustomOpts {
/// Additional time to wait in before hook.
#[clap(
#[arg(
long,
parse(try_from_str = humantime::parse_duration)
value_parser = humantime::parse_duration,
)]
pre_pause: Option<Duration>,
}
Expand Down Expand Up @@ -205,7 +200,7 @@ async fn main() {
#
#[derive(clap::Args)]
struct CustomOpts {
#[clap(subcommand)]
#[command(subcommand)]
command: Option<SubCommand>,
}

Expand All @@ -217,9 +212,9 @@ enum SubCommand {
#[derive(clap::Args)]
struct Smoke {
/// Additional time to wait in before hook.
#[clap(
#[arg(
long,
parse(try_from_str = humantime::parse_duration)
value_parser = humantime::parse_duration,
)]
pre_pause: Option<Duration>,
}
Expand Down
2 changes: 1 addition & 1 deletion book/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false

[dependencies]
async-trait = "0.1"
clap = { version = "3.0", features = ["derive"] }
clap = { version = "4.0.6", features = ["derive", "wrap_help"] }
cucumber = { path = "../..", features = ["libtest", "output-json", "output-junit"] }
futures = "0.3"
humantime = "2.1"
Expand Down
28 changes: 15 additions & 13 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ pub use clap::{Args, Parser};
/// #[derive(clap::Args)] // also re-exported as `cli::Args`
/// struct CustomOpts {
/// /// Additional time to wait in before hook.
/// #[clap(
/// #[arg(
/// long,
/// parse(try_from_str = humantime::parse_duration)
/// value_parser = humantime::parse_duration,
/// )]
/// pre_pause: Option<Duration>,
/// }
Expand All @@ -79,7 +79,7 @@ pub use clap::{Args, Parser};
/// [`Runner`]: crate::Runner
/// [`Writer`]: crate::Writer
#[derive(Debug, Clone, clap::Parser)]
#[clap(
#[command(
name = "cucumber",
about = "Run the tests, pet a dog!",
long_about = "Run the tests, pet a dog!"
Expand All @@ -92,7 +92,7 @@ where
Custom: Args,
{
/// Regex to filter scenarios by their name.
#[clap(
#[arg(
short = 'n',
long = "name",
value_name = "regex",
Expand All @@ -105,35 +105,35 @@ where
///
/// Note: Tags from Feature, Rule and Scenario are merged together on
/// filtering, so be careful about conflicting tags on different levels.
#[clap(
#[arg(
short = 't',
long = "tags",
value_name = "tagexpr",
conflicts_with = "re-filter",
conflicts_with = "re_filter",
global = true
)]
pub tags_filter: Option<TagOperation>,

/// [`Parser`] CLI options.
///
/// [`Parser`]: crate::Parser
#[clap(flatten)]
#[command(flatten)]
pub parser: Parser,

/// [`Runner`] CLI options.
///
/// [`Runner`]: crate::Runner
#[clap(flatten)]
#[command(flatten)]
pub runner: Runner,

/// [`Writer`] CLI options.
///
/// [`Writer`]: crate::Writer
#[clap(flatten)]
#[command(flatten)]
pub writer: Writer,

/// Additional custom CLI options.
#[clap(flatten)]
#[command(flatten)]
pub custom: Custom,
}

Expand Down Expand Up @@ -168,6 +168,7 @@ pub trait Colored {

/// Empty CLI options.
#[derive(Args, Clone, Copy, Debug)]
#[group(skip)]
pub struct Empty;

impl Colored for Empty {}
Expand All @@ -186,7 +187,7 @@ impl Colored for Empty {}
///
/// #[derive(cli::Args)] // re-export of `clap::Args`
/// struct Cli {
/// #[clap(long)]
/// #[arg(long)]
/// custom_option: Option<String>,
/// }
///
Expand Down Expand Up @@ -267,13 +268,14 @@ impl Colored for Empty {}
///
/// [`Writer`]: crate::Writer
#[derive(Args, Debug)]
#[group(skip)]
pub struct Compose<L: Args, R: Args> {
/// Left [`clap::Args`] deriver.
#[clap(flatten)]
#[command(flatten)]
pub left: L,

/// Right [`clap::Args`] deriver.
#[clap(flatten)]
#[command(flatten)]
pub right: R,
}

Expand Down
4 changes: 2 additions & 2 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ where
/// #[derive(clap::Args)]
/// struct CustomCli {
/// /// Additional time to wait in a before hook.
/// #[clap(
/// #[arg(
/// long,
/// parse(try_from_str = humantime::parse_duration)
/// value_parser = humantime::parse_duration,
/// )]
/// before_time: Option<Duration>,
/// }
Expand Down
19 changes: 8 additions & 11 deletions src/parser/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use std::{
borrow::Cow,
fmt,
path::{Path, PathBuf},
str::FromStr,
vec,
Expand All @@ -30,10 +29,11 @@ use super::{Error as ParseError, Parser};

/// CLI options of a [`Basic`] [`Parser`].
#[derive(clap::Args, Debug)]
#[group(skip)]
pub struct Cli {
/// Glob pattern to look for feature files with. By default, looks for
/// `*.feature`s in the path configured tests runner.
#[clap(long = "input", short = 'i', value_name = "glob", global = true)]
#[arg(long = "input", short = 'i', value_name = "glob", global = true)]
pub features: Option<Walker>,
}

Expand Down Expand Up @@ -91,7 +91,9 @@ impl<I: AsRef<Path>> Parser<I> for Basic {

let features = || {
let features = if let Some(walker) = cli.features {
walk(walker.0)
walk(globwalk::glob(walker.0).unwrap_or_else(|e| {
unreachable!("Invalid glob pattern: {e}")
}))
} else {
let feats_path = match get_features_path() {
Ok(p) => p,
Expand Down Expand Up @@ -163,18 +165,13 @@ pub struct UnsupportedLanguageError(
);

/// Wrapper over [`GlobWalker`] implementing a [`FromStr`].
pub struct Walker(GlobWalker);

impl fmt::Debug for Walker {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Walker").finish_non_exhaustive()
}
}
#[derive(Clone, Debug)]
pub struct Walker(String);

impl FromStr for Walker {
type Err = globwalk::GlobError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
globwalk::glob(s).map(Self)
globwalk::glob(s).map(|_| Self(s.to_owned()))
}
}
Loading