|
| 1 | +# Zerv Flow CLI Command Design |
| 2 | + |
| 3 | +**Status**: Planned |
| 4 | +**Priority**: High |
| 5 | +**Context**: Simplified CLI design for `zerv flow` command, mirroring `zerv version` structure with flow-specific pre-release management. |
| 6 | + |
| 7 | +## Command Structure |
| 8 | + |
| 9 | +```bash |
| 10 | +zerv flow [OPTIONS] |
| 11 | +``` |
| 12 | + |
| 13 | +**Single command only** - no subcommands. |
| 14 | + |
| 15 | +## Core Arguments |
| 16 | + |
| 17 | +### Output Options (same as zerv version) |
| 18 | + |
| 19 | +```bash |
| 20 | +-o, --output-format <FORMAT> Output format [default: semver] [possible values: semver, pep440, zerv] |
| 21 | +-t, --output-template <TEMPLATE> Custom output template using handlebars syntax |
| 22 | +-p, --output-prefix <PREFIX> Add prefix to output version |
| 23 | +``` |
| 24 | + |
| 25 | +### Input Options (same as zerv version) |
| 26 | + |
| 27 | +```bash |
| 28 | +-s, --source <SOURCE> Version source [default: git] [possible values: git, hg, bzr, svn] |
| 29 | +-f, --input-format <FORMAT> Input format [default: semver] [possible values: semver, pep440, calver, docker, raw] |
| 30 | +-d, --directory <DIR> Repository directory [default: current directory] |
| 31 | +``` |
| 32 | + |
| 33 | +### Flow-Specific Options |
| 34 | + |
| 35 | +```bash |
| 36 | +-l, --pre-release-label <LABEL> Pre-release label [default: auto-detect from branch] [possible values: alpha, beta, rc] |
| 37 | +-n, --pre-release-num <NUM> Pre-release number [default: hash from branch name] |
| 38 | + --branch-rules <RON> Custom branch rules (RON format) [default: release-only] |
| 39 | + --bumped-branch <BRANCH> Override branch name for pre-release resolution (same as zerv version) |
| 40 | + --bumped-branch-hash-length <LENGTH> Branch hash length for pre-release numbers [default: 5] [range: 4..16] |
| 41 | + --post-mode <TYPE> Post calculation mode [default: tag] [possible values: tag, commit] |
| 42 | + --build-context Include build context (+branch.commit) in output [default: true] |
| 43 | + --no-build-context Exclude build context from output |
| 44 | + --dev-ts Include dev timestamp for dirty working directory [default: auto-detect] |
| 45 | + --no-dev-ts Exclude dev timestamp from output |
| 46 | + --with-pre-release Include pre-release/post-release but no build context |
| 47 | + --base-only Base version only (major.minor.patch) |
| 48 | +-v, --verbose Show verbose output including version resolution details |
| 49 | +-h, --help Print help |
| 50 | +-V, --version Print version |
| 51 | +``` |
| 52 | + |
| 53 | +## Pre-release Resolution Logic |
| 54 | + |
| 55 | +### Default Behavior (no flags) |
| 56 | + |
| 57 | +- **Label**: `alpha` with hash-based number from branch name (e.g., `feature/auth` → `alpha.12345`) |
| 58 | +- **Number**: Hash derived from branch name using `--bumped-branch-hash-length` |
| 59 | + |
| 60 | +### Post Distance Logic |
| 61 | + |
| 62 | +**Configurable post distance calculation with two methods:** |
| 63 | + |
| 64 | +#### Tag Distance (default) |
| 65 | + |
| 66 | +- **`post`** increments when new tags are created on the branch |
| 67 | +- **Reference point**: Last tag created on the branch |
| 68 | +- **`post.0`**: Exactly when a new tag is created |
| 69 | +- **Untagged commits**: Same `post` number, different `dev.timestamp` |
| 70 | +- **Use case**: Release branches where you want to tag specific milestones |
| 71 | + |
| 72 | +``` |
| 73 | +release/1 created → tag v1.0.1-rc.1.post.1 |
| 74 | +1 commit → v1.0.1-rc.1.post.1.dev.1729924622 (same post) |
| 75 | +2 commits → v1.0.1-rc.1.post.1.dev.1729924623 (same post) |
| 76 | +new tag → v1.0.1-rc.1.post.2 (post increments) |
| 77 | +``` |
| 78 | + |
| 79 | +#### Commit Distance |
| 80 | + |
| 81 | +- **`post`** counts commits since branch creation point |
| 82 | +- **Reference point**: Branch creation from tag/branch |
| 83 | +- **`post.0`**: Exactly when branch is created |
| 84 | +- **All commits**: Increment `post` with each commit |
| 85 | +- **Use case**: Development branches tracking total work done |
| 86 | + |
| 87 | +``` |
| 88 | +develop created from v1.0.0 → 1.0.1-beta.1.post.0 |
| 89 | +1 commit → 1.0.1-beta.1.post.1 |
| 90 | +2 commits → 1.0.1-beta.1.post.2 |
| 91 | +``` |
| 92 | + |
| 93 | +**Control via `--post-mode` argument:** |
| 94 | + |
| 95 | +- `--post-mode tag` (default): Tag-based post calculation |
| 96 | +- `--post-mode commit`: Commit-based post calculation |
| 97 | + |
| 98 | +### Branch Pattern Detection (`--branch-rules`) |
| 99 | + |
| 100 | +**Configurable branch rules via RON string or use defaults:** |
| 101 | + |
| 102 | +```bash |
| 103 | +# Use custom branch rules |
| 104 | +zerv flow --branch-rules "[(pattern: \"develop\", pre_release: \"beta\", number: \"1\", post_mode: \"commit\")]" |
| 105 | + |
| 106 | +# Use default rules (no argument needed) |
| 107 | +zerv flow --branch-rules |
| 108 | +``` |
| 109 | + |
| 110 | +**Default rules (when no RON provided):** |
| 111 | + |
| 112 | +```ron |
| 113 | +[ |
| 114 | + (pattern: "develop", pre_release: "beta", number: "1", post_mode: "commit"), |
| 115 | + (pattern: "release/*", pre_release: "rc", post_mode: "tag"), |
| 116 | +] |
| 117 | +``` |
| 118 | + |
| 119 | +**Branch rules can specify:** |
| 120 | + |
| 121 | +- **pattern**: Branch name pattern to match |
| 122 | +- **pre_release**: Pre-release type (alpha, beta, rc) |
| 123 | +- **number**: Fixed number or hash-based |
| 124 | +- **post_mode**: Tag or commit distance calculation |
| 125 | + |
| 126 | +**Advanced RON configuration examples:** |
| 127 | + |
| 128 | +```ron |
| 129 | +( |
| 130 | + [ |
| 131 | + (pattern: "develop", pre_release: "beta", number: "1", post_mode: "commit"), |
| 132 | + (pattern: "release/*", pre_release: "rc", post_mode: "tag"), |
| 133 | + (pattern: "feature/*", pre_release: "alpha", post_mode: "tag"), |
| 134 | + (pattern: "hotfix/*", pre_release: "alpha", post_mode: "tag"), |
| 135 | + ], |
| 136 | +) |
| 137 | +``` |
| 138 | + |
| 139 | +**Pattern matching rules:** |
| 140 | + |
| 141 | +- **Exact match**: `develop` matches only `develop` branch |
| 142 | +- **Wildcard match**: `release/*` matches branches starting with `release/` |
| 143 | +- **Number extraction**: For wildcard patterns, tries to extract number: |
| 144 | + - `release/1` → extracts `1` |
| 145 | + - `release/1/xxxxx` → extracts `1` |
| 146 | + - `release/feature-name` (no number) → uses hash-based numbering |
| 147 | + |
| 148 | +**Branch behaviors (not on tagged commits):** |
| 149 | + |
| 150 | +- `main` → `1.1.0-alpha.1.post.2+main.2.a1b2c3d` |
| 151 | +- `develop` → `1.0.1-beta.1.post.3+develop.3.c2d3e4f` |
| 152 | +- `release/1` → `1.0.1-rc.1.post.1+release.1.1.e4f5g6h` |
| 153 | +- `release/hotfix` → `1.0.1-rc.12345.post.1+release.hotfix.1.g5h6i7j` |
| 154 | +- `feature/auth` → `1.0.1-alpha.54321.post.2+feature.auth.2.h6i7j8k` |
| 155 | + |
| 156 | +**On tagged commits:** Clean versions (e.g., `1.0.0`, `1.0.1`) |
| 157 | + |
| 158 | +**Branch name processing:** |
| 159 | + |
| 160 | +- Slashes (`/`) converted to dots (`.`): `feature/auth` → `feature.auth` |
| 161 | +- Hash generation uses simplified branch name: `feature.auth` → `12345` |
| 162 | + |
| 163 | +### Manual Override |
| 164 | + |
| 165 | +**Mutually exclusive with `--pre-release-from-branch`:** |
| 166 | + |
| 167 | +```bash |
| 168 | +# Force specific pre-release type and number |
| 169 | +zerv flow --pre-release-label beta --pre-release-num 1 |
| 170 | + |
| 171 | +# Force rc for release-like branches |
| 172 | +zerv flow --pre-release-label rc --pre-release-num 2 |
| 173 | + |
| 174 | +# Force alpha for feature branches (uses hash by default) |
| 175 | +zerv flow --pre-release-label alpha |
| 176 | +``` |
| 177 | + |
| 178 | +### Branch Override |
| 179 | + |
| 180 | +**Test different branch scenarios without switching branches:** |
| 181 | + |
| 182 | +```bash |
| 183 | +zerv flow --bumped-branch develop --pre-release-from-branch |
| 184 | +zerv flow --bumped-branch release/1 --pre-release-from-branch |
| 185 | +``` |
| 186 | + |
| 187 | +## Output Modes |
| 188 | + |
| 189 | +### Full Output (default) |
| 190 | + |
| 191 | +``` |
| 192 | +1.0.1-alpha.12345.post.2.dev.1729924622+feature.auth.2.a1b2c3d |
| 193 | +``` |
| 194 | + |
| 195 | +### Pre-release Output (`--with-pre-release`) |
| 196 | + |
| 197 | +``` |
| 198 | +1.0.1-alpha.12345.post.2 |
| 199 | +``` |
| 200 | + |
| 201 | +### Base-Only Output (`--base-only`) |
| 202 | + |
| 203 | +``` |
| 204 | +1.0.1 |
| 205 | +``` |
| 206 | + |
| 207 | +### On Reference Point (post.0) |
| 208 | + |
| 209 | +``` |
| 210 | +1.0.1-rc.1.post.0 (exactly on branch point/tag) |
| 211 | +``` |
| 212 | + |
| 213 | +## Format Variations |
| 214 | + |
| 215 | +### SemVer (default) |
| 216 | + |
| 217 | +``` |
| 218 | +1.0.1-alpha.12345.post.1.dev.1729924622+feature.auth.1.a1b2c3d |
| 219 | +``` |
| 220 | + |
| 221 | +### PEP440 |
| 222 | + |
| 223 | +``` |
| 224 | +1.0.1a12345.post1.dev1729924622 |
| 225 | +``` |
| 226 | + |
| 227 | +### Zerv (RON format) |
| 228 | + |
| 229 | +``` |
| 230 | +<zerv ron> |
| 231 | +``` |
| 232 | + |
| 233 | +## Usage Examples |
| 234 | + |
| 235 | +### Basic Usage |
| 236 | + |
| 237 | +```bash |
| 238 | +# Generate flow version with automatic pre-release |
| 239 | +zerv flow |
| 240 | + |
| 241 | +# Enable branch pattern detection (GitFlow) |
| 242 | +zerv flow --pre-release-from-branch |
| 243 | + |
| 244 | +# Force specific pre-release type |
| 245 | +zerv flow --pre-release-label beta |
| 246 | + |
| 247 | +# Include pre-release/post-release but no build context |
| 248 | +zerv flow --with-pre-release |
| 249 | + |
| 250 | +# Base version only |
| 251 | +zerv flow --base-only |
| 252 | +``` |
| 253 | + |
| 254 | +### Advanced Usage |
| 255 | + |
| 256 | +```bash |
| 257 | +# Complete control over pre-release |
| 258 | +zerv flow --bumped-branch release/1 --pre-release-from-branch |
| 259 | + |
| 260 | +# Custom template output |
| 261 | +zerv flow --output-template "v{{version}}-{{pre_release}}" |
| 262 | + |
| 263 | +# Different repository directory |
| 264 | +zerv flow --directory ../other-repo |
| 265 | + |
| 266 | +# Verbose output |
| 267 | +zerv flow --verbose |
| 268 | +``` |
| 269 | + |
| 270 | +## Future Configuration |
| 271 | + |
| 272 | +**RON configuration files (not in initial implementation):** |
| 273 | + |
| 274 | +```ron |
| 275 | +# .zerv.ron |
| 276 | +( |
| 277 | + branch_patterns: [ |
| 278 | + (pattern: "develop", pre_release: "beta", number: "1"), |
| 279 | + (pattern: "release", pre_release: "rc"), |
| 280 | + (pattern: "feature", pre_release: "alpha"), |
| 281 | + (pattern: "hotfix", pre_release: "alpha"), |
| 282 | + ], |
| 283 | +) |
| 284 | +``` |
| 285 | + |
| 286 | +**Usage:** |
| 287 | + |
| 288 | +```bash |
| 289 | +zerv flow --config .zerv.ron |
| 290 | +``` |
| 291 | + |
| 292 | +## Key Design Principles |
| 293 | + |
| 294 | +1. **Mirror zerv version**: Same output/input options structure |
| 295 | +2. **Intelligent defaults**: Smart branch-based pre-release detection |
| 296 | +3. **Flexible overrides**: Manual control when needed |
| 297 | +4. **Honest versioning**: Never hides Git state, always accurate |
| 298 | +5. **Clean alternatives**: `--with-pre-release` and `--base-only` for simplified output |
| 299 | + |
| 300 | +--- |
| 301 | + |
| 302 | +**Next Steps**: Implement basic `zerv flow` command structure and integrate with existing `zerv version` functions. |
0 commit comments