Skip to content

Commit 93cb063

Browse files
authored
feat: update -C flag support for changing directory (#95)
1 parent 5db7c6c commit 93cb063

File tree

18 files changed

+1621
-108
lines changed

18 files changed

+1621
-108
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
description: CLI implementation standards for zerv including core commands, pipeline architecture, argument structures, and format validation patterns
3+
globs: **/*.rs,**/src/cli/**/*.rs,**/tests/**/*.rs
4+
alwaysApply: true
5+
---
6+
7+
# CLI Implementation Standards
8+
9+
## Core Commands
10+
11+
### `zerv version [OPTIONS]`
12+
13+
Main version processing pipeline with composable operations.
14+
15+
### `zerv check <version> [OPTIONS]`
16+
17+
Validation-only command for version strings.
18+
19+
## Pipeline Architecture
20+
21+
```
22+
Input → Version Object → Zerv Object → Transform → Output Version Object → Display
23+
```
24+
25+
## Key Implementation Patterns
26+
27+
### Version Command Args Structure
28+
29+
```rust
30+
#[derive(Parser)]
31+
struct VersionArgs {
32+
version: Option<String>,
33+
#[arg(long, default_value = "git")]
34+
source: String,
35+
#[arg(long, default_value = "zerv-default")]
36+
schema: String,
37+
#[arg(long)]
38+
schema_ron: Option<String>,
39+
#[arg(long)]
40+
output_format: Option<String>,
41+
}
42+
```
43+
44+
### Check Command Args Structure
45+
46+
```rust
47+
#[derive(Parser)]
48+
struct CheckArgs {
49+
version: String,
50+
#[arg(long)]
51+
format: Option<String>, // pep440, semver, auto-detect (default)
52+
}
53+
```
54+
55+
### Core Pipeline Function
56+
57+
```rust
58+
pub fn run_version_pipeline(args: VersionArgs) -> Result<String> {
59+
// 1. Get VCS data
60+
let vcs_data = detect_vcs(current_dir())?.get_vcs_data()?;
61+
62+
// 2. Convert to ZervVars
63+
let vars = vcs_data_to_zerv_vars(vcs_data)?;
64+
65+
// 3. Apply schema and output format
66+
match args.output_format.as_deref() {
67+
Some("pep440") => Ok(PEP440::from_zerv(&vars)?.to_string()),
68+
Some("semver") => Ok(SemVer::from_zerv(&vars)?.to_string()),
69+
_ => Ok(vars.to_string()),
70+
}
71+
}
72+
```
73+
74+
## State-Based Versioning Tiers
75+
76+
**Tier 1** (Tagged, clean): `major.minor.patch`
77+
**Tier 2** (Distance, clean): `major.minor.patch.post<distance>+branch.<commit>`
78+
**Tier 3** (Dirty): `major.minor.patch.dev<timestamp>+branch.<commit>`
79+
80+
## Format Flag Validation Pattern
81+
82+
```rust
83+
// Error if conflicting format flags used
84+
if args.format.is_some() && (args.input_format.is_some() || args.output_format.is_some()) {
85+
return Err(ZervError::ConflictingFlags(
86+
"Cannot use --format with --input-format or --output-format".to_string()
87+
));
88+
}
89+
```
90+
91+
## Check Command Auto-Detection Pattern
92+
93+
```rust
94+
fn run_check_command(args: CheckArgs) -> Result<()> {
95+
match args.format.as_deref() {
96+
Some("pep440") => {
97+
PEP440::parse(&args.version)?;
98+
println!("✓ Valid PEP440 version");
99+
}
100+
Some("semver") => {
101+
SemVer::parse(&args.version)?;
102+
println!("✓ Valid SemVer version");
103+
}
104+
None => {
105+
// Auto-detect format
106+
let pep440_valid = PEP440::parse(&args.version).is_ok();
107+
let semver_valid = SemVer::parse(&args.version).is_ok();
108+
109+
match (pep440_valid, semver_valid) {
110+
(true, false) => println!("✓ Valid PEP440 version"),
111+
(false, true) => println!("✓ Valid SemVer version"),
112+
(true, true) => {
113+
println!("✓ Valid PEP440 version");
114+
println!("✓ Valid SemVer version");
115+
}
116+
(false, false) => return Err(ZervError::InvalidVersion(args.version)),
117+
}
118+
}
119+
Some(format) => return Err(ZervError::UnknownFormat(format.to_string())),
120+
}
121+
Ok(())
122+
}
123+
```
124+
125+
## Essential CLI Options
126+
127+
### Input Sources
128+
129+
- `--source git` (default) - Auto-detect Git
130+
- `--source string <version>` - Parse version string
131+
132+
### Schema Control
133+
134+
- `--schema zerv-default` (default) - Tier-aware schema
135+
- `--schema-ron <ron>` - Custom RON schema
136+
137+
### Output Control
138+
139+
- `--output-format <format>` - Target format: pep440, semver
140+
- `--output-template <template>` - Custom template string
141+
- `--output-prefix [prefix]` - Add prefix (defaults to "v")

.cursor/rules/dev-workflow.mdc

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
description: Development workflow standards and processes for the zerv project including git practices, testing, and deployment
3+
globs: **/*.rs,**/*.md,**/*.yml,**/*.yaml,**/*.toml,**/Makefile
4+
alwaysApply: true
5+
---
6+
7+
# Development Workflow Rules
8+
9+
## MANDATORY: Always Check .dev First
10+
11+
Before performing ANY coding task, **read `.dev/00-README.md`** for complete project context and workflow.
12+
13+
## .dev Document Numbering
14+
15+
**Rule**: All .dev documents use sequential numbering to indicate creation order:
16+
17+
- `00-***.md`: Created at same point in time (current state)
18+
- `01-***.md`: Next development phase
19+
- `02-***.md`: Following phase
20+
- etc.
21+
22+
**Higher numbers = more recent/updated plans**
23+
24+
Always verify against actual codebase - higher numbered docs are more likely to be current.
25+
26+
## Essential Commands
27+
28+
✅ Use `make` commands (defined in `.dev/00-README.md`)
29+
⚠️ Ensure `make lint` and `make test` always pass before committing
30+
31+
## Testing Strategy
32+
33+
**For Amazon Q (AI Assistant):**
34+
35+
- ALWAYS use `make lint` and `make test` for validation
36+
37+
## Error Handling Standards
38+
39+
- Use `zerv::error::ZervError` for all custom errors
40+
- Implement proper error propagation with `?` operator
41+
- Include context in error messages for debugging
42+
- Use `io::Error::other()` instead of `io::Error::new(io::ErrorKind::Other, ...)`
43+
44+
## Performance Standards
45+
46+
- Parse 1000+ versions in <100ms
47+
- Minimal VCS command calls (batch when possible)
48+
- Use compiled regex patterns for speed
49+
- Zero-copy string operations where possible
50+
51+
## Architecture Patterns
52+
53+
- **Universal Format**: Component-based system with variable references
54+
- **Multi-Format Support**: PEP440, SemVer, template-based custom formats
55+
- **State-Based Tiers**: Tagged/Distance/Dirty states determine version components
56+
- **Pipeline Architecture**: Input → Parse → Transform → Output
57+
58+
**Error Standard Violations Check:**
59+
60+
When user mentions:
61+
62+
- "check error standards"
63+
- "find error violations"
64+
- "audit error handling"
65+
- "error compliance check"
66+
67+
→ Search codebase for violations:
68+
69+
- `io::Error::new(io::ErrorKind::Other` patterns
70+
- Missing `ZervError` usage in custom error cases
71+
- Direct `unwrap()` or `expect()` in production code
72+
- Error messages without context
73+
74+
## Code Reuse Standards
75+
76+
**ALWAYS check existing utilities first:**
77+
78+
- Check `src/test_utils/` before creating new test utilities
79+
- Reuse `TestDir`, `GitOperations` trait, and other existing infrastructure
80+
- Use `get_git_impl()` for environment-aware Git operations
81+
- Prefer `GitOperations` trait methods over direct Docker/Native calls
82+
- Avoid duplicating code across different files
83+
- Look for existing helper functions before implementing new ones
84+
85+
**Code Reuse Violations Check:**
86+
87+
When user mentions:
88+
89+
- "check code reuse"
90+
- "find duplicated code"
91+
- "audit code duplication"
92+
- "redundant code check"
93+
94+
→ Search codebase for violations:
95+
96+
- Duplicated test setup patterns
97+
- Direct `DockerGit`/`NativeGit` usage instead of `get_git_impl()`
98+
- Reimplemented Git operations instead of using `GitOperations` trait
99+
- Similar helper functions across files
100+
- Unused existing utilities in `src/test_utils/git/`

0 commit comments

Comments
 (0)