Skip to content

Commit d503ad3

Browse files
authored
Add global rb.toml file support and gem.toml/rbproject.toml run scripts support. (#1)
* Add global rb.toml file support. * Add rbproject.toml basic support. * Add 'rb run' command for project script execution Introduces the 'rb run' (and alias 'rb r') command to execute project scripts defined in rbproject.toml, with support for listing available scripts, script descriptions, and error handling. Updates documentation and integration tests to cover new functionality, and refactors CLI command registration and environment presentation for project script management. * Update Project.Integration.Tests.ps1 * Add rb init command, add more shell tests. * Add changelog entry. * Delegate run to exec command. This way it can share more advanced flows like automatically resolving bundle... * Add gem.toml support.
1 parent fdf3b1d commit d503ad3

28 files changed

+4613
-53
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Configuration file support via `rb.toml` for global settings
12+
- Project script management with `rbproject.toml` and `rb run` command
13+
- Project bootstrap script with `rb init`
14+
1015
## [0.1.0] - 2025-09-26
1116

1217
### Added
@@ -24,4 +29,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2429

2530
---
2631

27-
*Distinguished releases crafted with appropriate ceremony by RubyElders.com*
32+
*Distinguished releases crafted with appropriate ceremony by RubyElders.com*

Cargo.lock

Lines changed: 88 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["crates/*"]
44

55
[workspace.package]
6-
version = "0.1.0"
6+
version = "0.2.0"
77
edition = "2024"
88
authors = ["RubyElders.com"]
99
description = "A sophisticated Ruby environment manager that orchestrates installations and gem collections with distinguished precision"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ Ruby Butler expects Ruby installations in `~/.rubies/` (the standard location fo
8989
- `rb exec` / `rb x` - Execute commands within meticulously prepared environments
9090
- `rb environment` / `rb env` - Display current environment composition
9191
- `rb sync` - Manually synchronize bundler environments (auto-triggered when needed)
92+
- `rb run` / `rb r` - Execute project scripts defined in `gem.toml` or `rbproject.toml`
93+
94+
## Configuration
95+
96+
- **`rb.toml`** - Global configuration file (in `%APPDATA%/rb/` or `~/.rb.toml`)
97+
- **`gem.toml`** or **`rbproject.toml`** - Project-level script definitions and metadata
9298

9399
## Development
94100

crates/rb-cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ log = "0.4"
2727
env_logger = "0.11"
2828
semver = "1.0.26"
2929
which = "6.0"
30+
toml = "0.8"
31+
serde = { version = "1.0", features = ["derive"] }
3032

3133
[dev-dependencies]
3234
rb-tests = { path = "../rb-tests" }

crates/rb-cli/src/bin/rb.rs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use rb_cli::{
3-
Cli, Commands, environment_command, exec_command, init_logger, resolve_search_dir,
4-
runtime_command, sync_command,
3+
Cli, Commands, environment_command, exec_command, init_command, init_logger,
4+
resolve_search_dir, run_command, runtime_command, sync_command,
55
};
66
use rb_core::butler::{ButlerError, ButlerRuntime};
77

@@ -53,15 +53,35 @@ fn main() {
5353

5454
let cli = Cli::parse();
5555

56-
// Initialize logger with the effective log level (considering -v/-vv flags)
56+
// Initialize logger early with the effective log level (considering -v/-vv flags)
57+
// This allows us to see config file loading and merging logs
5758
init_logger(cli.effective_log_level());
5859

60+
// Merge config file defaults with CLI arguments
61+
let cli = match cli.with_config_defaults() {
62+
Ok(cli) => cli,
63+
Err(e) => {
64+
eprintln!("Configuration error: {}", e);
65+
std::process::exit(1);
66+
}
67+
};
68+
69+
// Handle init command early - doesn't require Ruby environment
70+
if let Commands::Init = cli.command {
71+
let current_dir = std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
72+
if let Err(e) = init_command(&current_dir) {
73+
eprintln!("{}", e);
74+
std::process::exit(1);
75+
}
76+
return;
77+
}
78+
5979
// Handle sync command differently since it doesn't use ButlerRuntime in the same way
6080
if let Commands::Sync = cli.command {
6181
if let Err(e) = sync_command(
62-
cli.rubies_dir.clone(),
63-
cli.ruby_version.clone(),
64-
cli.gem_home.clone(),
82+
cli.config.rubies_dir.clone(),
83+
cli.config.ruby_version.clone(),
84+
cli.config.gem_home.clone(),
6585
) {
6686
eprintln!("Sync failed: {}", e);
6787
std::process::exit(1);
@@ -70,13 +90,13 @@ fn main() {
7090
}
7191

7292
// Resolve search directory for Ruby installations
73-
let rubies_dir = resolve_search_dir(cli.rubies_dir);
93+
let rubies_dir = resolve_search_dir(cli.config.rubies_dir);
7494

7595
// Perform comprehensive environment discovery once
7696
let butler_runtime = match ButlerRuntime::discover_and_compose_with_gem_base(
7797
rubies_dir,
78-
cli.ruby_version,
79-
cli.gem_home,
98+
cli.config.ruby_version,
99+
cli.config.gem_home,
80100
) {
81101
Ok(runtime) => runtime,
82102
Err(e) => match e {
@@ -109,11 +129,18 @@ fn main() {
109129
runtime_command(&butler_runtime);
110130
}
111131
Commands::Environment => {
112-
environment_command(&butler_runtime);
132+
environment_command(&butler_runtime, cli.project_file);
113133
}
114134
Commands::Exec { args } => {
115135
exec_command(butler_runtime, args);
116136
}
137+
Commands::Run { script, args } => {
138+
run_command(butler_runtime, script, args, cli.project_file);
139+
}
140+
Commands::Init => {
141+
// Already handled above
142+
unreachable!()
143+
}
117144
Commands::Sync => {
118145
// Already handled above
119146
unreachable!()

0 commit comments

Comments
 (0)