Skip to content

Commit e5cef6b

Browse files
committed
cargo-rail: feat(config): add cargo rail config sync for config upgrades; add a new command that safely updates rail.toml when upgrading cargo-rail versions.
The command: - Adds missing config fields with sensible defaults (27 fields) - Union-merges targets from TOML and GitHub workflow YAML files - Preserves all existing user values, comments, and formatting - Supports --check mode for CI/pre-commit hooks Schema coverage: - [unify]: 16 fields (including new msrv_source, preserve_features) - [release]: 10 fields - [change-detection]: 1 field (infrastructure) This replaces the deprecated `cargo rail unify sync` command which only handled target detection. Users upgrading from v0.1.0 to v0.4.0 can now run `cargo rail config sync` to see all available configuration options. Exit codes: 0 = up to date, 1 = changes needed (--check), 2 = error
1 parent 06bcc4e commit e5cef6b

File tree

13 files changed

+1112
-427
lines changed

13 files changed

+1112
-427
lines changed

.config/rail.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ targets = [
2121
"aarch64-unknown-linux-gnu",
2222
"x86_64-pc-windows-msvc",
2323
"x86_64-unknown-linux-gnu",
24+
# Tier 2 (Common)
25+
"aarch64-unknown-linux-musl",
26+
"x86_64-unknown-linux-musl",
2427
# Other
2528
"aarch64-pc-windows-msvc",
2629
]
@@ -40,6 +43,8 @@ detect_unused = true # Detect unused dependencies (default: true)
4043
remove_unused = true # Auto-remove unused deps when applying (default: true)
4144
max_backups = 2 # Number of backup files to keep (default: 3)
4245
prune_dead_features = true # Remove features never enabled in resolved graph (default: true)
46+
msrv_source = "max" # How to compute MSRV: deps, workspace, max (default: max)
47+
preserve_features = [] # Features to preserve from pruning (glob patterns)
4348

4449

4550
[release]

docs/commands.md

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,18 @@ Usage: cargo rail unify [OPTIONS] [COMMAND]
151151
152152
Commands:
153153
undo Restore manifests from a previous backup
154-
sync Re-detect and sync targets to rail.toml
155154
help Print this message or the help of the given subcommand(s)
156155
157156
Options:
158157
-q, --quiet
159158
Suppress progress messages (for CI/automation)
160159
161-
--json
162-
Output in JSON format (shorthand for -f json)
163-
164160
-c, --check
165161
Dry-run mode: preview changes without modifying files
166162
163+
--json
164+
Output in JSON format (shorthand for -f json)
165+
167166
-f, --format <FORMAT>
168167
Output format
169168
@@ -203,8 +202,6 @@ Examples:
203202
cargo rail unify --show-diff # Show manifest changes
204203
cargo rail unify undo # Restore from backup
205204
cargo rail unify undo --list # List available backups
206-
cargo rail unify sync --check # Preview target sync
207-
cargo rail unify sync # Re-detect and merge targets into rail.toml
208205
```
209206

210207
---
@@ -227,34 +224,6 @@ Options:
227224

228225
---
229226

230-
### cargo rail unify sync
231-
232-
```
233-
Re-detect and sync targets to rail.toml
234-
235-
Scans workspace for target triples (rust-toolchain.toml, .cargo/config.toml, etc.) and merges any new targets into your rail.toml configuration. Preserves existing targets and all other settings.
236-
237-
Usage: cargo rail unify sync [OPTIONS]
238-
239-
Options:
240-
-c, --check
241-
Preview changes without modifying rail.toml
242-
243-
-q, --quiet
244-
Suppress progress messages (for CI/automation)
245-
246-
--json
247-
Output in JSON format (shorthand for -f json)
248-
249-
-h, --help
250-
Print help (see a summary with '-h')
251-
252-
-V, --version
253-
Print version
254-
```
255-
256-
---
257-
258227
## cargo rail init
259228

260229
```
@@ -704,6 +673,7 @@ Usage: cargo rail config [OPTIONS] <COMMAND>
704673
705674
Commands:
706675
validate Validate the configuration file
676+
sync Sync configuration: add missing fields and update targets
707677
help Print this message or the help of the given subcommand(s)
708678
709679
Options:
@@ -722,6 +692,8 @@ Options:
722692
Examples:
723693
cargo rail config validate # Validate rail.toml
724694
cargo rail config validate -f json # JSON output for CI
695+
cargo rail config sync --check # Preview config updates
696+
cargo rail config sync # Add missing fields, sync targets
725697
```
726698

727699
---
@@ -760,3 +732,47 @@ Options:
760732
-V, --version
761733
Print version
762734
```
735+
736+
---
737+
738+
### cargo rail config sync
739+
740+
```
741+
Sync configuration: add missing fields and update targets
742+
743+
Scans the workspace for target triples and adds any missing config fields with their default values. Preserves all existing settings, comments, and formatting.
744+
745+
Use this after upgrading cargo-rail to get new configuration options.
746+
747+
Usage: cargo rail config sync [OPTIONS]
748+
749+
Options:
750+
-c, --check
751+
Preview changes without modifying rail.toml
752+
753+
-q, --quiet
754+
Suppress progress messages (for CI/automation)
755+
756+
-f, --format <FORMAT>
757+
Output format
758+
759+
Possible values:
760+
- text: Human-readable text output (default)
761+
- json: Machine-readable JSON output
762+
- names-only: Names only, one per line
763+
- cargo-args: Cargo -p flag format: -p crate1 -p crate2
764+
- github: GitHub Actions output format for $GITHUB_OUTPUT
765+
- github-matrix: GitHub Actions matrix format for strategy.matrix
766+
- jsonl: JSON Lines format (one object per line)
767+
768+
[default: text]
769+
770+
--json
771+
Output in JSON format (shorthand for -f json)
772+
773+
-h, --help
774+
Print help (see a summary with '-h')
775+
776+
-V, --version
777+
Print version
778+
```

src/commands/cli.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ Examples:
7878
cargo rail unify --backup # Apply with backup
7979
cargo rail unify --show-diff # Show manifest changes
8080
cargo rail unify undo # Restore from backup
81-
cargo rail unify undo --list # List available backups
82-
cargo rail unify sync --check # Preview target sync
83-
cargo rail unify sync # Re-detect and merge targets into rail.toml";
81+
cargo rail unify undo --list # List available backups";
8482

8583
const SPLIT_HELP: &str = "\
8684
Examples:
@@ -128,7 +126,9 @@ Examples:
128126
const CONFIG_HELP: &str = "\
129127
Examples:
130128
cargo rail config validate # Validate rail.toml
131-
cargo rail config validate -f json # JSON output for CI";
129+
cargo rail config validate -f json # JSON output for CI
130+
cargo rail config sync --check # Preview config updates
131+
cargo rail config sync # Add missing fields, sync targets";
132132

133133
/// Available subcommands
134134
#[derive(Subcommand)]
@@ -303,6 +303,21 @@ pub enum ConfigCommand {
303303
#[arg(long, short = 'f', default_value_t, value_enum)]
304304
format: OutputFormat,
305305
},
306+
/// Sync configuration: add missing fields and update targets
307+
///
308+
/// Scans the workspace for target triples and adds any missing config
309+
/// fields with their default values. Preserves all existing settings,
310+
/// comments, and formatting.
311+
///
312+
/// Use this after upgrading cargo-rail to get new configuration options.
313+
Sync {
314+
/// Preview changes without modifying rail.toml
315+
#[arg(long, short = 'c')]
316+
check: bool,
317+
/// Output format
318+
#[arg(long, short = 'f', default_value_t, value_enum)]
319+
format: OutputFormat,
320+
},
306321
}
307322

308323
/// Subcommands for `cargo rail unify`
@@ -317,16 +332,6 @@ pub enum UnifyCommand {
317332
#[arg(long = "backup-id")]
318333
backup_id: Option<String>,
319334
},
320-
/// Re-detect and sync targets to rail.toml
321-
///
322-
/// Scans workspace for target triples (rust-toolchain.toml, .cargo/config.toml, etc.)
323-
/// and merges any new targets into your rail.toml configuration.
324-
/// Preserves existing targets and all other settings.
325-
Sync {
326-
/// Preview changes without modifying rail.toml
327-
#[arg(long, short = 'c')]
328-
check: bool,
329-
},
330335
}
331336

332337
/// Subcommands for `cargo rail split`
@@ -436,7 +441,7 @@ impl Commands {
436441
ReleaseCommand::Run { format, .. } | ReleaseCommand::Check { format, .. } => format.is_json_like(),
437442
},
438443
Commands::Config { command } => match command {
439-
ConfigCommand::Validate { format } => format.is_json_like(),
444+
ConfigCommand::Validate { format } | ConfigCommand::Sync { format, .. } => format.is_json_like(),
440445
},
441446
_ => false,
442447
}
@@ -458,7 +463,7 @@ impl Commands {
458463
} => *format = OutputFormat::Json,
459464
Commands::Release { .. } => {}
460465
Commands::Config { command } => match command {
461-
ConfigCommand::Validate { format } => *format = OutputFormat::Json,
466+
ConfigCommand::Validate { format } | ConfigCommand::Sync { format, .. } => *format = OutputFormat::Json,
462467
},
463468
_ => {}
464469
}

0 commit comments

Comments
 (0)