cvm_cli 1.0.8

A powerful command-line tool for managing semantic versioning of Rust crates. Easily bump versions (major, minor, patch), update Cargo.toml files, and streamline your release workflow with automated version management.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# CVM - Crate Version Manager

[![Crates.io](https://img.shields.io/crates/v/cvm_cli.svg)](https://crates.io/crates/cvm_cli)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A powerful command-line tool for managing semantic versioning of Rust crates in both single-crate and workspace projects.

## Features

- ๐Ÿš€ **Interactive Version Bumping**: Select crates and bump types (major, minor, patch) interactively
- ๐Ÿ“ฆ **Workspace Support**: Manage multiple crates in a Cargo workspace
- ๐Ÿ”„ **Change Queue System**: Stage version changes and apply them all at once
- ๐Ÿงช **Prerelease Mode**: Built-in support for canary/alpha/beta releases with automatic prerelease numbering
- ๐Ÿ“ **Change Summaries**: Require descriptions for all version changes
- ๐ŸŽฏ **Semantic Versioning**: Full compliance with [SemVer]https://semver.org/ specification

## Installation

```bash
cargo install cvm_cli
```

Or build from source:

```bash
git clone https://github.com/lucasaarch/cvm
cd cvm
cargo install --path .
```

## Quick Start

### Initialize CVM in your project

```bash
cd your-rust-project
cvm setup
```

This creates:
- `.cvm/config.toml` - Configuration file
- `.cvm/changes/` - Directory for pending version changes
- `.cvm/README.md` - Information about CVM

### Basic Workflow

1. **Initialize CVM** (first time only):
   ```bash
   cvm setup
   ```

2. **Stage a version change** (interactive mode):
   ```bash
   cvm
   ```
   This will prompt you to select crates and bump types (major, minor, or patch).

3. **Apply all staged changes**:
   ```bash
   cvm apply
   ```

### Prerelease Workflow

1. **Start prerelease mode**:
   ```bash
   cvm pre start canary
   ```
   This saves the current version as the base and enables prerelease mode.

2. **Stage and apply changes** (they will be prerelease versions):
   ```bash
   cvm
   cvm apply
   ```

3. **Exit prerelease mode** when ready for production:
   ```bash
   cvm pre exit
   ```

## How It Works

### Change Queue

When you run `cvm` without arguments, it creates timestamped change files in `.cvm/changes/`. Each file contains:
- A summary of the change
- Which crates to bump (major, minor, or patch)
- Whether it was created in prerelease mode

Running `cvm apply` processes all change files in chronological order and updates the `Cargo.toml` files accordingly.

### Prerelease Mode

Prerelease mode intelligently handles version bumps:

**Example flow starting from `0.1.0`:**

```bash
cvm pre start canary      # Saves base version: 0.1.0
```

Then applying changes sequentially:
- `patch` โ†’ `0.1.0-canary.0` (first prerelease of this base)
- `patch` โ†’ `0.1.0-canary.1` (increments prerelease number)
- `minor` โ†’ `0.2.0-canary.0` (new base: 0.1.0 + minor = 0.2.0)
- `patch` โ†’ `0.2.0-canary.1` (same base, increment number)
- `minor` โ†’ `0.2.0-canary.2` (base 0.1.0 + minor = 0.2.0, same as current)
- `major` โ†’ `1.0.0-canary.0` (new base: 0.1.0 + major = 1.0.0)

**Rules:**
- **PATCH** in prerelease: Always keeps the current base version, increments prerelease number
- **MINOR/MAJOR** in prerelease: Calculates new base from stored base version
  - If different from current base: applies bump and resets to `.0`
  - If same as current base: increments prerelease number

## Commands

### `cvm setup`
Initialize CVM in the current project. Creates configuration files and directories.

**Example:**
```bash
cvm setup
```

**Output:**
```
โœ… CVM initialized successfully!

Configuration file created at: .cvm/config.toml
Change files will be stored in: .cvm/changes/

Next steps:
  1. Run 'cvm' to create version changes interactively
  2. Run 'cvm apply' to apply pending changes
  3. Run 'cvm status' to check for pending changes
```

### `cvm` (no arguments)
Interactive mode to select crates and bump types. Creates a change file in `.cvm/changes/`.

**Example:**
```bash
cvm
# Select crates for major bump: [none]
# Select crates for minor bump: [my-crate]
# Select crates for patch bump: [none]
# Summary: Add new feature X
```

### `cvm apply`
Applies all pending changes in chronological order.

**Example:**
```bash
cvm apply
# Applying update: Add new feature X
#   my-crate minor โ†’ 0.2.0
# All updates applied successfully!
```

**Options:**
- `--dry-run`: Preview changes without applying them

### `cvm status`
Check for pending version changes.

**Example:**
```bash
cvm status
```

Returns exit code 0 if no pending changes, exit code 1 if there are pending changes (useful for CI/CD).

### `cvm info`
Get crate information as JSON. Useful for extracting version numbers and crate metadata in CI/CD pipelines.

**Example:**
```bash
cvm info
# [{"name":"my-crate","version":"1.0.0","path":"Cargo.toml"}]
```

**Options:**
- `--format <FORMAT>`: Output format (default: json)

### `cvm publish`
Publish crates to crates.io.

**Example:**
```bash
cvm publish
```

**Options:**
- `--dry-run`: Show what would be published without making changes
- `--token <TOKEN>`: Cargo registry token (overrides CARGO_REGISTRY_TOKEN env var)
- `--allow-dirty`: Allow publishing with uncommitted changes

**Output:**
The command outputs JSON at the end with published crate information:
```
::cvm-output-json::[{"name":"my-crate","version":"1.0.0"}]
```
This makes it easy to parse in CI/CD scripts.

### `cvm pre start [identifier]`
Enables prerelease mode with the specified identifier (e.g., `canary`, `alpha`, `beta`, `rc`).

**Examples:**
```bash
cvm pre start canary
cvm pre start alpha
cvm pre start rc
```

### `cvm pre exit`
Disables prerelease mode and clears stored base versions.

**Example:**
```bash
cvm pre exit
# Prerelease mode exited.
```

## File Structure

```
your-project/
โ”œโ”€โ”€ .cvm/
โ”‚   โ”œโ”€โ”€ config.toml           # CVM configuration
โ”‚   โ”œโ”€โ”€ changes/              # Pending version changes
โ”‚   โ”‚   โ”œโ”€โ”€ 1234567890.toml
โ”‚   โ”‚   โ””โ”€โ”€ 1234567891.toml
โ”‚   โ””โ”€โ”€ README.md             # Auto-generated info
โ”œโ”€โ”€ Cargo.toml
โ””โ”€โ”€ src/
```

### `.cvm/config.toml`

Stores CVM configuration:

```toml
# CVM Configuration

[pre]
enabled = true
identifier = "canary"

[pre.base_versions]
my-crate = "0.1.0"
```

### `.cvm/changes/1234567890.toml`

```toml
[update]
summary = "Add new feature X"
major = []
minor = ["my-crate"]
patch = []
pre = false
```

## Use Cases

### Single Crate Project
Perfect for managing versions of a single library or binary crate.

### Workspace Project
Manage multiple related crates with independent versioning:
- Select which crates to bump
- Different bump types for different crates
- Apply all changes atomically

### Continuous Deployment
1. Developers stage changes with `cvm` as they work
2. CI/CD applies changes with `cvm apply` before publishing
3. Prerelease mode for canary deployments

### Release Management
- Use prerelease mode for beta testing
- Stage multiple changes before release
- Apply all changes at once when ready

## CI/CD Integration

CVM is designed to work seamlessly in CI/CD pipelines. Here's a typical workflow:

### Checking for Pending Changes

Use `cvm status` to check if there are pending version changes:

```bash
cvm status
```

- **Exit code 0**: No pending changes
- **Exit code 1**: There are pending changes (useful for CI conditionals)

### Dry Run

Preview what would be applied without making changes:

```bash
cvm apply --dry-run
```

### Example GitHub Actions Workflow

```yaml
name: Version Management

on:
  push:
    branches: [canary]

jobs:
  apply-versions:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      
      - name: Install CVM
        run: cargo install cvm
      
      - name: Check for pending changes
        id: check
        run: |
          if ! cvm status; then
            echo "has_changes=true" >> $GITHUB_OUTPUT
          fi
      
      - name: Apply version changes
        if: steps.check.outputs.has_changes == 'true'
        run: cvm apply
      
      - name: Commit changes
        if: steps.check.outputs.has_changes == 'true'
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Cargo.toml */Cargo.toml
          git commit -m "chore: apply version bumps"
          git push
```

### Typical CI/CD Flow

1. **Development Branch** (`canary`):
   - Developers create changes: `cvm` โ†’ select crates โ†’ add summary
   - Commit changes to `.cvm/changes/` directory
   - Push to canary branch

2. **CI Pipeline Runs**:
   - Check for pending changes: `cvm status`
   - Apply changes: `cvm apply`
   - Run tests with new versions
   - Commit updated `Cargo.toml` files
   - Create PR to main or commit directly

3. **Production Branch** (`main`):
   - Merge PR with version bumps
   - Publish to crates.io: `cvm publish`

### Extracting Version Information in Scripts

Use `cvm info` to extract version information programmatically:

```bash
# Get current version for a single crate project
VERSION=$(cvm info | jq -r '.[0].version')
echo "Current version: $VERSION"

# Get all crate names and versions
cvm info | jq -r '.[] | "\(.name): \(.version)"'

# Check if a specific crate exists
HAS_CRATE=$(cvm info | jq -r '.[] | select(.name == "my-crate") | .name')
```

When using `cvm publish`, extract the JSON output:

```bash
# Capture publish output
OUTPUT=$(cvm publish 2>&1)

# Extract JSON from output
JSON=$(echo "$OUTPUT" | grep "::cvm-output-json::" | sed 's/.*::cvm-output-json:://')

# Parse published crates
echo "$JSON" | jq -r '.[] | "Published \(.name) v\(.version)"'
```

## Best Practices

1. **Always add meaningful summaries**: They serve as a changelog for your version bumps
2. **Use prerelease mode for testing**: Test breaking changes with canary releases
3. **Commit `.cvm/` to version control**: Share pending changes with your team
4. **Apply changes before publishing**: Run `cvm apply` before `cvm publish`
5. **Use `--dry-run` in CI**: Preview changes before applying them
6. **Check status in pipelines**: Use `cvm status` exit codes for conditional logic

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Authors

- Lucas Arch <luketsx@icloud.com>

## Links

- [Repository]https://github.com/lucasaarch/cvm
- [Crates.io]https://crates.io/crates/cvm_cli
- [Documentation]https://docs.rs/cvm_cli