Commits on Source (2)
This diff is collapsed.
[package]
name = "ruled-labels"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
license-file = "LICENSE"
......@@ -12,7 +12,7 @@ hubcaps = "0.6"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = { version = "0.9", optional = false }
termion = "1.5"
termion = "2"
semver = { version = "1.0", features = ["serde"] }
regex = "1"
anyhow = "1.0"
......
......@@ -49,6 +49,8 @@ You can now remove the leading `,` that is not useful:
labels_args=${labels: :-1}
Before using the `labels_args`, you want to ensure you are using `IFS=","` so your shell does not split one label containing a space into 2 strings made of a valid label and one that will fail.
And finally run the check:
ruled-labels check --dev --labels $labels_args
......
......@@ -34,6 +34,8 @@ You can now remove the leading `,` that is not useful:
labels_args=${labels: :-1}
WARNING: Before using the `labels_args`, you want to ensure you are using `IFS=","` so your shell does not split one label containing a space into 2 strings made of a valid label and one that will fail.
And finally run the check:
ruled-labels check --dev --labels $labels_args
......
......@@ -66,7 +66,12 @@ fn main() -> Result<(), Box<dyn Error>> {
log::debug!("check: {:#?}", cmd_opts);
let specs: Specs = Specs::load(&cmd_opts.spec_file)?;
let label_ids: HashSet<LabelId> = cmd_opts.labels.iter().map(|s| s.id).collect();
let label_ids: HashSet<LabelId> = if !cmd_opts.no_label {
cmd_opts.labels.iter().map(|s| s.id).collect()
} else {
HashSet::new()
};
let res =
specs.run_checks(&label_ids, true, !opts.no_color, opts.dev, cmd_opts.tags, &None);
let aggregated_result = res.iter().fold(true, |acc, x| match x {
......
......@@ -69,6 +69,10 @@ pub struct CheckOpts {
#[clap(long, short, required = true, num_args=1.., value_delimiter = ',')]
pub labels: Vec<ParsedLabel>,
/// Depending on your rules, if may be ok to have no labels.
#[clap(long, short, conflicts_with = "labels")]
pub no_label: bool,
/// Show details about the rules of the faulty tests
#[clap(long)]
pub faulty: bool,
......
......@@ -122,6 +122,7 @@ impl TryFrom<&str> for ParsedLabel {
impl From<String> for ParsedLabel {
fn from(s: String) -> Self {
println!("s = {:?}", s);
let id = LabelId::from_str(&s).unwrap();
let mut s = s;
let description = s.drain(0..2).as_str().to_string();
......
......@@ -169,5 +169,12 @@ mod cli_tests {
.assert();
assert.failure().code(1);
}
#[test]
fn it_passes_when_no_labels_required() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd.arg("check").arg("./tests/specs_mini.yaml").arg("--no-label").assert();
assert.success().code(0);
}
}
}
---
name: Mini Specs
version: 0.1.0
description: A mini set of rules that is pretty friendly
labels:
- name: A1-foo
description: Foo
color: d73a4a
- name: A2-bar
description: Bar
color: d73a4a
# parser:
# id: ^(\w\d).*$ # default
# description: ^\w\d-(.*?)$ # Optional, un-used
rules:
- name: Foo needs Bar
description: |
It is ok to pass no labels, but if foo is set, bar is required``
spec:
when: !one_of
- A1
require: !one_of
- A2
exclude: ~
name: Name of the test
spec_file: specs.yaml
spec_file: specs_ok.yaml
specs:
- name: Should Fail
......