Skip to content

Commit 92e6292

Browse files
committed
Add flag to current command that auto installs missing versions
1 parent cbe8c6b commit 92e6292

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: internal/cli/cli.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ func Execute(version string) {
8787
Name: "no-header",
8888
Usage: "Whether or not to print a header line",
8989
},
90+
&cli.BoolFlag{
91+
Name: "install-missing",
92+
Usage: "Install missing versions for installed plugins",
93+
},
9094
},
9195
Action: func(cCtx *cli.Context) error {
9296
tool := cCtx.Args().Get(0)
9397

9498
noHeader := cCtx.Bool("no-header")
95-
return currentCommand(logger, tool, noHeader)
99+
install := cCtx.Bool("install-missing")
100+
return currentCommand(logger, tool, noHeader, install)
96101
},
97102
},
98103
{
@@ -367,7 +372,7 @@ Completions are available for: %v`, shell, strings.Join(completions.Names(), ",
367372
}
368373

369374
// This function is a whole mess and needs to be refactored
370-
func currentCommand(logger *log.Logger, tool string, noHeader bool) error {
375+
func currentCommand(logger *log.Logger, tool string, noHeader bool, install bool) error {
371376
conf, err := config.LoadConfig()
372377
if err != nil {
373378
logger.Printf("error loading config: %s", err)
@@ -401,6 +406,11 @@ func currentCommand(logger *log.Logger, tool string, noHeader bool) error {
401406
for _, plugin := range allPlugins {
402407
toolversion, versionFound, versionInstalled := getVersionInfo(conf, plugin, currentDir)
403408
formatCurrentVersionLine(w, plugin, toolversion, versionFound, versionInstalled, err)
409+
410+
if !versionInstalled && install && len(toolversion.Versions) > 0 {
411+
version := toolversion.Versions[0]
412+
versions.InstallOneVersion(conf, plugin, version, false, w, os.Stderr)
413+
}
404414
}
405415
w.Flush()
406416
return nil

0 commit comments

Comments
 (0)