Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integration-test-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
39 changes: 31 additions & 8 deletions src/cmd/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -137,5 +158,7 @@ func showSingleVersion(runtimeName string) {
}

func init() {
currentCmd.Flags().BoolVarP(&currentYes, "yes", "y", false, "Automatically install missing versions without prompting")
currentCmd.Flags().BoolVarP(&currentNoInstall, "no-install", "n", false, "Skip install prompts entirely")
rootCmd.AddCommand(currentCmd)
}