From ed9522596a451606bd654f3cc9707e1a4e9f13ba Mon Sep 17 00:00:00 2001 From: "Calvin A. Allen" Date: Sat, 13 Dec 2025 19:17:12 -0500 Subject: [PATCH] feat(current): add --yes flag to skip install prompts Add --yes/-y and --no-install/-n flags to the current command: - --yes: automatically install missing versions without prompting - --no-install: skip install prompts entirely (for CI environments) Update integration tests to use --no-install flag to prevent hanging on stdin in CI environments. Fixes #136 --- .github/workflows/integration-test-node.yml | 4 +- .github/workflows/integration-test-python.yml | 4 +- .github/workflows/integration-test-ruby.yml | 4 +- src/cmd/current.go | 39 +++++++++++++++---- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.github/workflows/integration-test-node.yml b/.github/workflows/integration-test-node.yml index b7d2ce3..bc6cb79 100644 --- a/.github/workflows/integration-test-node.yml +++ b/.github/workflows/integration-test-node.yml @@ -131,7 +131,7 @@ jobs: - name: "Verify global version via current" run: | cd "$TEST_WORKSPACE" - CURRENT=$(./dtvem${{ matrix.ext }} current node) + CURRENT=$(./dtvem${{ matrix.ext }} current node --no-install) echo "Current node version: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '20.18.0' }}"* ]]; then echo "ERROR: Expected ${{ inputs.version1 || '20.18.0' }} but got $CURRENT" @@ -173,7 +173,7 @@ jobs: mkdir -p test-project cd test-project ../dtvem${{ matrix.ext }} local node ${{ inputs.version1 || '20.18.0' }} - CURRENT=$(../dtvem${{ matrix.ext }} current node) + CURRENT=$(../dtvem${{ matrix.ext }} current node --no-install) echo "Current node version in test-project: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '20.18.0' }}"* ]]; then echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '20.18.0' }} but got $CURRENT" diff --git a/.github/workflows/integration-test-python.yml b/.github/workflows/integration-test-python.yml index 867a397..428be21 100644 --- a/.github/workflows/integration-test-python.yml +++ b/.github/workflows/integration-test-python.yml @@ -131,7 +131,7 @@ jobs: - name: "Verify global version via current" run: | cd "$TEST_WORKSPACE" - CURRENT=$(./dtvem${{ matrix.ext }} current python) + CURRENT=$(./dtvem${{ matrix.ext }} current python --no-install) echo "Current python version: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '3.11.9' }}"* ]]; then echo "ERROR: Expected ${{ inputs.version1 || '3.11.9' }} but got $CURRENT" @@ -173,7 +173,7 @@ jobs: mkdir -p test-project cd test-project ../dtvem${{ matrix.ext }} local python ${{ inputs.version1 || '3.11.9' }} - CURRENT=$(../dtvem${{ matrix.ext }} current python) + CURRENT=$(../dtvem${{ matrix.ext }} current python --no-install) echo "Current python version in test-project: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '3.11.9' }}"* ]]; then echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '3.11.9' }} but got $CURRENT" diff --git a/.github/workflows/integration-test-ruby.yml b/.github/workflows/integration-test-ruby.yml index 90a72b6..6d62ae6 100644 --- a/.github/workflows/integration-test-ruby.yml +++ b/.github/workflows/integration-test-ruby.yml @@ -131,7 +131,7 @@ jobs: - name: "Verify global version via current" run: | cd "$TEST_WORKSPACE" - CURRENT=$(./dtvem${{ matrix.ext }} current ruby) + CURRENT=$(./dtvem${{ matrix.ext }} current ruby --no-install) echo "Current ruby version: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '3.3.6' }}"* ]]; then echo "ERROR: Expected ${{ inputs.version1 || '3.3.6' }} but got $CURRENT" @@ -173,7 +173,7 @@ jobs: mkdir -p test-project cd test-project ../dtvem${{ matrix.ext }} local ruby ${{ inputs.version1 || '3.3.6' }} - CURRENT=$(../dtvem${{ matrix.ext }} current ruby) + CURRENT=$(../dtvem${{ matrix.ext }} current ruby --no-install) echo "Current ruby version in test-project: $CURRENT" if [[ "$CURRENT" != *"${{ inputs.version1 || '3.3.6' }}"* ]]; then echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '3.3.6' }} but got $CURRENT" diff --git a/src/cmd/current.go b/src/cmd/current.go index a604627..b9e1c90 100644 --- a/src/cmd/current.go +++ b/src/cmd/current.go @@ -9,6 +9,11 @@ import ( "github.com/spf13/cobra" ) +var ( + currentYes bool + currentNoInstall bool +) + // runtimeStatus holds the status of a configured runtime type runtimeStatus struct { provider runtime.Provider @@ -29,15 +34,17 @@ Examples: Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { - showAllVersions() + showAllVersions(currentYes, currentNoInstall) } else { - showSingleVersion(args[0]) + showSingleVersion(args[0], currentYes, currentNoInstall) } }, } -// showAllVersions displays all configured runtimes and prompts to install missing ones -func showAllVersions() { +// showAllVersions displays all configured runtimes and prompts to install missing ones. +// If noInstall is true, install prompts are skipped entirely. +// If yes is true, install prompts are auto-accepted. +func showAllVersions(yes, noInstall bool) { providers := runtime.GetAll() if len(providers) == 0 { @@ -82,10 +89,16 @@ func showAllVersions() { fmt.Println(table.Render()) + // Skip install prompts if --no-install flag is set + if noInstall { + return + } + // Prompt to install missing versions if len(missing) > 0 { fmt.Println() - if ui.PromptInstallMissing(missing) { + shouldInstall := yes || ui.PromptInstallMissing(missing) + if shouldInstall { for _, rs := range missing { ui.Info("Installing %s %s...", rs.provider.DisplayName(), rs.version) if err := rs.provider.Install(rs.version); err != nil { @@ -98,8 +111,10 @@ func showAllVersions() { } } -// showSingleVersion displays a single runtime version and prompts to install if missing -func showSingleVersion(runtimeName string) { +// showSingleVersion displays a single runtime version and prompts to install if missing. +// If noInstall is true, install prompts are skipped entirely. +// If yes is true, install prompts are auto-accepted. +func showSingleVersion(runtimeName string, yes, noInstall bool) { provider, err := runtime.Get(runtimeName) if err != nil { ui.Error("%v", err) @@ -126,8 +141,14 @@ func showSingleVersion(runtimeName string) { table.AddRow(provider.DisplayName(), version, tui.CrossMark+" not installed") fmt.Println(table.Render()) + // Skip install prompts if --no-install flag is set + if noInstall { + return + } + fmt.Println() - if ui.PromptInstall(provider.DisplayName(), version) { + shouldInstall := yes || ui.PromptInstall(provider.DisplayName(), version) + if shouldInstall { if err := provider.Install(version); err != nil { ui.Error("Failed to install %s %s: %v", provider.DisplayName(), version, err) return @@ -137,5 +158,7 @@ func showSingleVersion(runtimeName string) { } func init() { + currentCmd.Flags().BoolVarP(¤tYes, "yes", "y", false, "Automatically install missing versions without prompting") + currentCmd.Flags().BoolVarP(¤tNoInstall, "no-install", "n", false, "Skip install prompts entirely") rootCmd.AddCommand(currentCmd) }