Skip to content

Commit 8099141

Browse files
committed
feat(cli): implement init command with platform selection
Add interactive platform selection to the init command, allowing users to choose which platforms to support. This helps keep repo size small by only including needed binaries. Features: - Interactive multi-select with pre-selected current platform - Non-interactive modes: --all-platforms, --current-platform-only - Explicit platform list: --platforms linux-amd64,macos-arm64 - Platform management: --add-platform, --remove-platform - Show configured platforms: --show-platforms New modules: - platform.rs: Platform detection and definitions - rnr_config.rs: .rnr/config.yaml management Smart wrapper scripts detect OS/architecture and provide helpful errors when a platform is not configured. Closes #10
1 parent 3e487b3 commit 8099141

8 files changed

Lines changed: 1031 additions & 83 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,157 @@ jobs:
225225
fi
226226
echo "✅ Nested task delegation passed"
227227
228+
# ==================== Init Command Tests ====================
229+
230+
- name: "Test: init --current-platform-only"
231+
shell: bash
232+
run: |
233+
INIT_DIR=$(mktemp -d)
234+
cd "$INIT_DIR"
235+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --current-platform-only
236+
237+
# Verify files were created
238+
if [ ! -f ".rnr/config.yaml" ]; then
239+
echo "ERROR: .rnr/config.yaml not created"
240+
exit 1
241+
fi
242+
if [ ! -d ".rnr/bin" ]; then
243+
echo "ERROR: .rnr/bin directory not created"
244+
exit 1
245+
fi
246+
if [ ! -f "rnr.yaml" ]; then
247+
echo "ERROR: rnr.yaml not created"
248+
exit 1
249+
fi
250+
if [ ! -f "rnr" ]; then
251+
echo "ERROR: rnr wrapper not created"
252+
exit 1
253+
fi
254+
if [ ! -f "rnr.cmd" ]; then
255+
echo "ERROR: rnr.cmd wrapper not created"
256+
exit 1
257+
fi
258+
259+
# Verify config has exactly one platform
260+
PLATFORM_COUNT=$(grep -c "^-" .rnr/config.yaml || echo "0")
261+
if [ "$PLATFORM_COUNT" != "1" ]; then
262+
echo "ERROR: Expected 1 platform, got $PLATFORM_COUNT"
263+
exit 1
264+
fi
265+
266+
echo "✅ init --current-platform-only passed"
267+
rm -rf "$INIT_DIR"
268+
269+
- name: "Test: init --platforms with multiple platforms"
270+
shell: bash
271+
run: |
272+
INIT_DIR=$(mktemp -d)
273+
cd "$INIT_DIR"
274+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --platforms linux-amd64,macos-arm64,windows-amd64
275+
276+
# Verify config has the right platforms
277+
if ! grep -q "linux-amd64" .rnr/config.yaml; then
278+
echo "ERROR: linux-amd64 not in config"
279+
exit 1
280+
fi
281+
if ! grep -q "macos-arm64" .rnr/config.yaml; then
282+
echo "ERROR: macos-arm64 not in config"
283+
exit 1
284+
fi
285+
if ! grep -q "windows-amd64" .rnr/config.yaml; then
286+
echo "ERROR: windows-amd64 not in config"
287+
exit 1
288+
fi
289+
290+
# Verify binaries exist
291+
if [ ! -f ".rnr/bin/rnr-linux-amd64" ]; then
292+
echo "ERROR: rnr-linux-amd64 binary not created"
293+
exit 1
294+
fi
295+
if [ ! -f ".rnr/bin/rnr-macos-arm64" ]; then
296+
echo "ERROR: rnr-macos-arm64 binary not created"
297+
exit 1
298+
fi
299+
if [ ! -f ".rnr/bin/rnr-windows-amd64.exe" ]; then
300+
echo "ERROR: rnr-windows-amd64.exe binary not created"
301+
exit 1
302+
fi
303+
304+
echo "✅ init --platforms passed"
305+
rm -rf "$INIT_DIR"
306+
307+
- name: "Test: init --add-platform and --remove-platform"
308+
shell: bash
309+
run: |
310+
INIT_DIR=$(mktemp -d)
311+
cd "$INIT_DIR"
312+
313+
# First init with one platform
314+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --platforms linux-amd64
315+
316+
# Add a platform
317+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --add-platform macos-arm64
318+
319+
if ! grep -q "macos-arm64" .rnr/config.yaml; then
320+
echo "ERROR: macos-arm64 not added to config"
321+
exit 1
322+
fi
323+
if [ ! -f ".rnr/bin/rnr-macos-arm64" ]; then
324+
echo "ERROR: rnr-macos-arm64 binary not created"
325+
exit 1
326+
fi
327+
328+
# Remove a platform
329+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --remove-platform linux-amd64
330+
331+
if grep -q "linux-amd64" .rnr/config.yaml; then
332+
echo "ERROR: linux-amd64 should have been removed from config"
333+
exit 1
334+
fi
335+
if [ -f ".rnr/bin/rnr-linux-amd64" ]; then
336+
echo "ERROR: rnr-linux-amd64 binary should have been removed"
337+
exit 1
338+
fi
339+
340+
echo "✅ init --add-platform and --remove-platform passed"
341+
rm -rf "$INIT_DIR"
342+
343+
- name: "Test: init --show-platforms"
344+
shell: bash
345+
run: |
346+
INIT_DIR=$(mktemp -d)
347+
cd "$INIT_DIR"
348+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --platforms linux-amd64,windows-amd64
349+
350+
OUTPUT=$($GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --show-platforms 2>&1)
351+
if ! echo "$OUTPUT" | grep -q "linux-amd64"; then
352+
echo "ERROR: --show-platforms should list linux-amd64"
353+
exit 1
354+
fi
355+
if ! echo "$OUTPUT" | grep -q "windows-amd64"; then
356+
echo "ERROR: --show-platforms should list windows-amd64"
357+
exit 1
358+
fi
359+
360+
echo "✅ init --show-platforms passed"
361+
rm -rf "$INIT_DIR"
362+
363+
- name: "Test: init refuses to remove last platform"
364+
shell: bash
365+
run: |
366+
INIT_DIR=$(mktemp -d)
367+
cd "$INIT_DIR"
368+
$GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --platforms linux-amd64
369+
370+
# Try to remove the only platform - should fail
371+
if $GITHUB_WORKSPACE/tests/${{ matrix.binary }} init --remove-platform linux-amd64 2>&1; then
372+
echo "ERROR: Should not be able to remove last platform"
373+
exit 1
374+
fi
375+
376+
echo "✅ init correctly refuses to remove last platform"
377+
rm -rf "$INIT_DIR"
378+
228379
# ==================== Error Cases ====================
229380

230381
- name: "Test: nonexistent task (should fail)"

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ thiserror = "1"
2323
# Cross-platform support
2424
dirs = "5"
2525

26+
# Interactive prompts
27+
dialoguer = "0.11"
28+
console = "0.15"
29+
2630
# HTTP client for init/upgrade
2731
reqwest = { version = "0.12", features = ["blocking"], default-features = false, optional = true }
2832

0 commit comments

Comments
 (0)