- Ruby 2.7+ (recommend 3.2+ for YJIT)
- Bundler (
gem install bundler)
- Rust 1.70+ (install from rustup.rs)
- Cargo (comes with Rust)
git clone https://github.com/ai-ptd-dev/basiccli
cd basicclibundle install./bin/compilebasiccli/
├── src/
│ ├── cli.rb # Ruby CLI entry point
│ ├── cli.rs # Rust CLI entry point (transpiled)
│ ├── commands/
│ │ ├── hello.rb # Ruby command
│ │ ├── hello.rs # Rust command (transpiled)
│ │ ├── version.rb
│ │ ├── version.rs
│ │ └── ...
│ └── utils/
│ ├── logger.rb # Ruby utility
│ ├── logger.rs # Rust utility (transpiled)
│ └── ...
├── spec/
│ ├── commands/
│ │ ├── hello_spec.rb # Ruby tests
│ │ ├── hello_test.rs # Rust tests
│ │ └── ...
│ └── spec_helper.rb
├── bin/
│ ├── basiccli-ruby # Ruby executable
│ ├── basiccli-rust # Rust executable
│ ├── compile # Build Rust binary
│ ├── test # Run Rust tests
│ ├── rspec # Run Ruby tests
│ └── lint # Lint both languages
└── docs/ # Documentation
# Using the script
./bin/basiccli-ruby hello "World"
# Direct execution
bundle exec ruby src/cli.rb hello "World"# First compile
./bin/compile
# Then run
./bin/basiccli-rust hello "World"
# Or directly
./target/release/basiccli-rust hello "World"# Basic greeting
./bin/basiccli-ruby hello "Alice"
# With options
./bin/basiccli-ruby hello "Bob" --uppercase --repeat 3# Human-readable
./bin/basiccli-ruby version
# JSON output
./bin/basiccli-ruby version --json# Run benchmarks
./bin/basiccli-ruby benchmark 1000
# Output formats
./bin/basiccli-ruby benchmark 1000 --output json
./bin/basiccli-ruby benchmark 1000 --output csv
# Verbose mode
./bin/basiccli-ruby benchmark 1000 --verbose# Process JSON file
./bin/basiccli-ruby process data.json
# With options
./bin/basiccli-ruby process data.json --pretty --statsCreate your command in src/commands/:
module BasicCli
module Commands
class MyCommand
def initialize(options = {})
@options = options
end
def execute
puts "Hello from MyCommand!"
end
end
end
endRegister in src/cli.rb:
desc "mycommand", "Description here"
def mycommand
command = Commands::MyCommand.new(options)
command.execute
endCreate spec/commands/mycommand_spec.rb:
RSpec.describe BasicCli::Commands::MyCommand do
it 'executes successfully' do
command = described_class.new
expect { command.execute }.to output(/Hello/).to_stdout
end
end./bin/rspecManually create src/commands/mycommand.rs:
pub struct MyCommand {
// fields
}
impl MyCommand {
pub fn new() -> Self {
Self {}
}
pub fn execute(&self) -> Result<()> {
println!("Hello from MyCommand!");
Ok(())
}
}./bin/compile
./bin/testBuilds the Rust binary with optimizations:
./bin/compileRuns Rust tests:
./bin/testRuns Ruby tests:
./bin/rspecLints and auto-fixes both Ruby and Rust:
./bin/lintCompare Ruby vs Rust performance:
# Ruby version
time ./bin/basiccli-ruby benchmark 1000
# Rust version
time ./bin/basiccli-rust benchmark 1000- Explore the code: Look at existing commands for patterns
- Add your command: Follow the development workflow
- Benchmark: Compare Ruby vs Rust performance
- Optimize: Profile and improve bottlenecks
- Deploy: Use the Rust binary in production
- Keep Ruby and Rust implementations functionally identical
- Use Ruby for rapid prototyping
- Transpile to Rust for production deployment
- Run both test suites to ensure parity
- Use the performance benchmarks to validate improvements