Skip to content

Commit 6552c06

Browse files
committed
fix: fix version args conflict cases
1 parent 7e51bca commit 6552c06

File tree

2 files changed

+58
-33
lines changed

2 files changed

+58
-33
lines changed

src/cli/version/args/validation.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@ pub struct Validation;
1111

1212
impl Validation {
1313
/// Validate main configuration
14-
pub fn validate_main(_main: &MainConfig) -> Result<(), ZervError> {
15-
// Main config validation (currently no conflicts to check)
14+
pub fn validate_main(main: &MainConfig) -> Result<(), ZervError> {
15+
// Check for --output-template conflicts
16+
if main.output_template.is_some() {
17+
if main.output_format != crate::utils::constants::formats::SEMVER {
18+
return Err(ZervError::ConflictingOptions(
19+
"Cannot use --output-template with --output-format. \
20+
Use --output-format alone for pure format output, \
21+
or --output-template alone for custom formatting"
22+
.to_string(),
23+
));
24+
}
25+
if main.output_prefix.is_some() {
26+
return Err(ZervError::ConflictingOptions(
27+
"Cannot use --output-template with --output-prefix. \
28+
Add the prefix directly in your template instead \
29+
(e.g., 'v{{major}}.{{minor}}.{{patch}}')"
30+
.to_string(),
31+
));
32+
}
33+
}
34+
1635
Ok(())
1736
}
1837

tests/integration_tests/version/main/templates.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -328,27 +328,6 @@ mod template_complex_scenarios {
328328
}
329329
}
330330

331-
mod template_with_output_prefix {
332-
use super::*;
333-
334-
#[rstest]
335-
#[case::v_prefix("v", "v1.2.3")]
336-
#[case::custom_prefix("Release-", "Release-1.2.3")]
337-
fn test_prefix_flag(#[case] prefix: &str, #[case] expected: &str) {
338-
let fixture = ZervFixture::new().with_version(1, 2, 3);
339-
let zerv_ron = fixture.build().to_string();
340-
341-
let output = TestCommand::new()
342-
.args_from_str(format!(
343-
"version --source stdin --output-template '{{{{major}}}}.{{{{minor}}}}.{{{{patch}}}}' --output-prefix {prefix}"
344-
))
345-
.stdin(zerv_ron)
346-
.assert_success();
347-
348-
assert_eq!(output.stdout().trim(), expected);
349-
}
350-
}
351-
352331
mod template_edge_cases {
353332
use super::*;
354333

@@ -399,23 +378,50 @@ mod template_with_schema {
399378
"Template should override schema output"
400379
);
401380
}
381+
}
382+
383+
mod template_validation_errors {
384+
use super::*;
402385

403386
#[test]
404-
fn test_template_with_format() {
405-
let fixture = ZervFixture::new()
406-
.with_version(1, 2, 3)
407-
.with_pre_release(PreReleaseLabel::Alpha, Some(1));
387+
fn test_template_conflicts_with_output_format() {
388+
let fixture = ZervFixture::new().with_version(1, 2, 3);
408389
let zerv_ron = fixture.build().to_string();
409390

410391
let output = TestCommand::new()
411-
.args_from_str("version --source stdin --output-format pep440 --output-template 'Custom: {{pep440}}'")
392+
.args_from_str("version --source stdin --output-format pep440 --output-template '{{major}}.{{minor}}.{{patch}}'")
412393
.stdin(zerv_ron)
413-
.assert_success();
394+
.assert_failure();
414395

415-
assert_eq!(
416-
output.stdout().trim(),
417-
"Custom: 1.2.3a1",
418-
"Template should use formatted version variable"
396+
let stderr = output.stderr();
397+
assert!(
398+
stderr.contains("Cannot use --output-template with --output-format"),
399+
"Should error when using --output-template with --output-format. Got stderr: {stderr}"
400+
);
401+
assert!(
402+
stderr.contains("Use --output-format alone for pure format output"),
403+
"Error message should explain the distinction between format and template. Got stderr: {stderr}"
404+
);
405+
}
406+
407+
#[test]
408+
fn test_template_conflicts_with_output_prefix() {
409+
let fixture = ZervFixture::new().with_version(1, 2, 3);
410+
let zerv_ron = fixture.build().to_string();
411+
412+
let output = TestCommand::new()
413+
.args_from_str("version --source stdin --output-template '{{major}}.{{minor}}.{{patch}}' --output-prefix v")
414+
.stdin(zerv_ron)
415+
.assert_failure();
416+
417+
let stderr = output.stderr();
418+
assert!(
419+
stderr.contains("Cannot use --output-template with --output-prefix"),
420+
"Should error when using --output-template with --output-prefix. Got stderr: {stderr}"
421+
);
422+
assert!(
423+
stderr.contains("Add the prefix directly in your template"),
424+
"Error message should suggest adding prefix in template. Got stderr: {stderr}"
419425
);
420426
}
421427
}

0 commit comments

Comments
 (0)