@@ -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
1318type 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
139160func 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