Skip to content

Commit 1f2371c

Browse files
authored
feat(current): add --yes flag to skip install prompts (#139)
1 parent 3bec118 commit 1f2371c

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

.github/workflows/integration-test-node.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
- name: "Verify global version via current"
132132
run: |
133133
cd "$TEST_WORKSPACE"
134-
CURRENT=$(./dtvem${{ matrix.ext }} current node)
134+
CURRENT=$(./dtvem${{ matrix.ext }} current node --no-install)
135135
echo "Current node version: $CURRENT"
136136
if [[ "$CURRENT" != *"${{ inputs.version1 || '20.18.0' }}"* ]]; then
137137
echo "ERROR: Expected ${{ inputs.version1 || '20.18.0' }} but got $CURRENT"
@@ -173,7 +173,7 @@ jobs:
173173
mkdir -p test-project
174174
cd test-project
175175
../dtvem${{ matrix.ext }} local node ${{ inputs.version1 || '20.18.0' }}
176-
CURRENT=$(../dtvem${{ matrix.ext }} current node)
176+
CURRENT=$(../dtvem${{ matrix.ext }} current node --no-install)
177177
echo "Current node version in test-project: $CURRENT"
178178
if [[ "$CURRENT" != *"${{ inputs.version1 || '20.18.0' }}"* ]]; then
179179
echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '20.18.0' }} but got $CURRENT"

.github/workflows/integration-test-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
- name: "Verify global version via current"
132132
run: |
133133
cd "$TEST_WORKSPACE"
134-
CURRENT=$(./dtvem${{ matrix.ext }} current python)
134+
CURRENT=$(./dtvem${{ matrix.ext }} current python --no-install)
135135
echo "Current python version: $CURRENT"
136136
if [[ "$CURRENT" != *"${{ inputs.version1 || '3.11.9' }}"* ]]; then
137137
echo "ERROR: Expected ${{ inputs.version1 || '3.11.9' }} but got $CURRENT"
@@ -173,7 +173,7 @@ jobs:
173173
mkdir -p test-project
174174
cd test-project
175175
../dtvem${{ matrix.ext }} local python ${{ inputs.version1 || '3.11.9' }}
176-
CURRENT=$(../dtvem${{ matrix.ext }} current python)
176+
CURRENT=$(../dtvem${{ matrix.ext }} current python --no-install)
177177
echo "Current python version in test-project: $CURRENT"
178178
if [[ "$CURRENT" != *"${{ inputs.version1 || '3.11.9' }}"* ]]; then
179179
echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '3.11.9' }} but got $CURRENT"

.github/workflows/integration-test-ruby.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
- name: "Verify global version via current"
132132
run: |
133133
cd "$TEST_WORKSPACE"
134-
CURRENT=$(./dtvem${{ matrix.ext }} current ruby)
134+
CURRENT=$(./dtvem${{ matrix.ext }} current ruby --no-install)
135135
echo "Current ruby version: $CURRENT"
136136
if [[ "$CURRENT" != *"${{ inputs.version1 || '3.3.6' }}"* ]]; then
137137
echo "ERROR: Expected ${{ inputs.version1 || '3.3.6' }} but got $CURRENT"
@@ -173,7 +173,7 @@ jobs:
173173
mkdir -p test-project
174174
cd test-project
175175
../dtvem${{ matrix.ext }} local ruby ${{ inputs.version1 || '3.3.6' }}
176-
CURRENT=$(../dtvem${{ matrix.ext }} current ruby)
176+
CURRENT=$(../dtvem${{ matrix.ext }} current ruby --no-install)
177177
echo "Current ruby version in test-project: $CURRENT"
178178
if [[ "$CURRENT" != *"${{ inputs.version1 || '3.3.6' }}"* ]]; then
179179
echo "ERROR: Local override failed. Expected ${{ inputs.version1 || '3.3.6' }} but got $CURRENT"

src/cmd/current.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12+
var (
13+
currentYes bool
14+
currentNoInstall bool
15+
)
16+
1217
// runtimeStatus holds the status of a configured runtime
1318
type runtimeStatus struct {
1419
provider runtime.Provider
@@ -29,15 +34,17 @@ Examples:
2934
Args: cobra.MaximumNArgs(1),
3035
Run: func(cmd *cobra.Command, args []string) {
3136
if len(args) == 0 {
32-
showAllVersions()
37+
showAllVersions(currentYes, currentNoInstall)
3338
} else {
34-
showSingleVersion(args[0])
39+
showSingleVersion(args[0], currentYes, currentNoInstall)
3540
}
3641
},
3742
}
3843

39-
// showAllVersions displays all configured runtimes and prompts to install missing ones
40-
func showAllVersions() {
44+
// showAllVersions displays all configured runtimes and prompts to install missing ones.
45+
// If noInstall is true, install prompts are skipped entirely.
46+
// If yes is true, install prompts are auto-accepted.
47+
func showAllVersions(yes, noInstall bool) {
4148
providers := runtime.GetAll()
4249

4350
if len(providers) == 0 {
@@ -82,10 +89,16 @@ func showAllVersions() {
8289

8390
fmt.Println(table.Render())
8491

92+
// Skip install prompts if --no-install flag is set
93+
if noInstall {
94+
return
95+
}
96+
8597
// Prompt to install missing versions
8698
if len(missing) > 0 {
8799
fmt.Println()
88-
if ui.PromptInstallMissing(missing) {
100+
shouldInstall := yes || ui.PromptInstallMissing(missing)
101+
if shouldInstall {
89102
for _, rs := range missing {
90103
ui.Info("Installing %s %s...", rs.provider.DisplayName(), rs.version)
91104
if err := rs.provider.Install(rs.version); err != nil {
@@ -98,8 +111,10 @@ func showAllVersions() {
98111
}
99112
}
100113

101-
// showSingleVersion displays a single runtime version and prompts to install if missing
102-
func showSingleVersion(runtimeName string) {
114+
// showSingleVersion displays a single runtime version and prompts to install if missing.
115+
// If noInstall is true, install prompts are skipped entirely.
116+
// If yes is true, install prompts are auto-accepted.
117+
func showSingleVersion(runtimeName string, yes, noInstall bool) {
103118
provider, err := runtime.Get(runtimeName)
104119
if err != nil {
105120
ui.Error("%v", err)
@@ -126,8 +141,14 @@ func showSingleVersion(runtimeName string) {
126141
table.AddRow(provider.DisplayName(), version, tui.CrossMark+" not installed")
127142
fmt.Println(table.Render())
128143

144+
// Skip install prompts if --no-install flag is set
145+
if noInstall {
146+
return
147+
}
148+
129149
fmt.Println()
130-
if ui.PromptInstall(provider.DisplayName(), version) {
150+
shouldInstall := yes || ui.PromptInstall(provider.DisplayName(), version)
151+
if shouldInstall {
131152
if err := provider.Install(version); err != nil {
132153
ui.Error("Failed to install %s %s: %v", provider.DisplayName(), version, err)
133154
return
@@ -137,5 +158,7 @@ func showSingleVersion(runtimeName string) {
137158
}
138159

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

0 commit comments

Comments
 (0)