Skip to content

Commit d953f1c

Browse files
ilslvtyranron
andauthored
Restore old CLI options (#137)
Co-authored-by: tyranron <tyranron@gmail.com>
1 parent 69d05a4 commit d953f1c

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
2121
- Replaced `#[given(step)]`, `#[when(step)]` and `#[then(step)]` function argument attributes with a single `#[step]`. ([#128])
2222
- Made test callbacks first argument `&mut World` instead of `World`. ([#128])
2323
- Made `#[step]` argument of step functions `Step` instead of `StepContext` again, while test callbacks still receive `StepContext` as a second parameter. ([#128])
24-
- CLI and [hooks](https://cucumber.io/docs/cucumber/api/#hooks) were removed, but are planned to be re-implemented with some changes in `0.11` release. ([#128])
24+
- Deprecated `--nocapture` and `--debug` CLI options to be completely redesigned in `0.11` release. ([#137])
25+
- [Hooks](https://cucumber.io/docs/cucumber/api/#hooks) were removed, but are planned to be re-implemented with some changes in `0.11` release. ([#128])
2526

2627
### Added
2728

2829
- Ability to run `Scenario`s concurrently. ([#128])
2930

3031
[#128]: /../../pull/128
32+
[#137]: /../../pull/137
3133

3234

3335

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macros = ["cucumber-codegen", "inventory"]
3131
[dependencies]
3232
async-trait = "0.1.40"
3333
atty = "0.2.14"
34+
clap = "3.0.0-beta.4"
3435
console = "0.14.1"
3536
derive_more = { version = "0.99.16", features = ["deref", "display", "error", "from"], default_features = false }
3637
either = "1.6"

src/cli.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2018-2021 Brendan Molloy <brendan@bbqsrc.net>,
2+
// Ilya Solovyiov <ilya.solovyiov@gmail.com>,
3+
// Kai Ren <tyranron@gmail.com>
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! CLI options.
12+
13+
use clap::Clap;
14+
use regex::Regex;
15+
16+
/// Run the tests, pet a dog!.
17+
///
18+
/// __WARNING__ ⚠️: This CLI exists only for backwards compatibility. In `0.11`
19+
/// it will be completely reworked:
20+
/// [cucumber-rs/cucumber#134][1].
21+
///
22+
/// [1]: https://github.com/cucumber-rs/cucumber/issues/134
23+
#[derive(Clap, Debug)]
24+
pub struct Opts {
25+
/// Regex to select scenarios from.
26+
#[clap(short = 'e', long = "expression", name = "regex")]
27+
pub filter: Option<Regex>,
28+
29+
/// __WARNING__ ⚠️: This option does nothing at the moment and is deprecated
30+
/// for removal in the next major release.
31+
/// Any output of step functions is not captured by default.
32+
#[clap(long)]
33+
pub nocapture: bool,
34+
35+
/// __WARNING__ ⚠️: This option does nothing at the moment and is deprecated
36+
/// for removal in the next major release.
37+
#[clap(long)]
38+
pub debug: bool,
39+
}

src/cucumber.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ use std::{
2020
path::Path,
2121
};
2222

23+
use clap::Clap as _;
2324
use futures::StreamExt as _;
2425
use regex::Regex;
2526

2627
use crate::{
27-
event, parser, runner, step, writer, ArbitraryWriter, FailureWriter,
28+
cli, event, parser, runner, step, writer, ArbitraryWriter, FailureWriter,
2829
Parser, Runner, ScenarioType, Step, World, Writer, WriterExt as _,
2930
};
3031

@@ -610,19 +611,7 @@ where
610611
///
611612
/// [`Feature`]: gherkin::Feature
612613
pub async fn run(self, input: I) -> Wr {
613-
let Cucumber {
614-
parser,
615-
runner,
616-
mut writer,
617-
..
618-
} = self;
619-
620-
let events_stream = runner.run(parser.parse(input));
621-
futures::pin_mut!(events_stream);
622-
while let Some(ev) = events_stream.next().await {
623-
writer.handle_event(ev).await;
624-
}
625-
writer
614+
self.filter_run(input, |_, _, _| true).await
626615
}
627616

628617
/// Runs [`Cucumber`] with [`Scenario`]s filter.
@@ -684,6 +673,7 @@ where
684673
///
685674
/// [`Feature`]: gherkin::Feature
686675
/// [`Scenario`]: gherkin::Scenario
676+
#[allow(clippy::non_ascii_literal)]
687677
pub async fn filter_run<F>(self, input: I, filter: F) -> Wr
688678
where
689679
F: Fn(
@@ -693,6 +683,29 @@ where
693683
) -> bool
694684
+ 'static,
695685
{
686+
let opts = cli::Opts::parse();
687+
if opts.nocapture {
688+
eprintln!(
689+
"WARNING ⚠️: This option does nothing at the moment and is \
690+
deprecated for removal in the next major release. \
691+
Any output of step functions is not captured by \
692+
default.",
693+
);
694+
}
695+
if opts.debug {
696+
eprintln!(
697+
"WARNING ⚠️: This option does nothing at the moment and is \
698+
deprecated for removal in the next major release.",
699+
);
700+
}
701+
let filter = move |f: &gherkin::Feature,
702+
r: Option<&gherkin::Rule>,
703+
s: &gherkin::Scenario| {
704+
opts.filter
705+
.as_ref()
706+
.map_or_else(|| filter(f, r, s), |f| f.is_match(&s.name))
707+
};
708+
696709
let Cucumber {
697710
parser,
698711
runner,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)]
3232
#![cfg_attr(docsrs, feature(doc_cfg))]
3333

34+
pub mod cli;
3435
mod cucumber;
3536
pub mod event;
3637
pub mod feature;

0 commit comments

Comments
 (0)