From 0f74bfff68a2bf6703ba9480b2569c1aa7e704dc Mon Sep 17 00:00:00 2001 From: Raj Chaudhuri Date: Fri, 3 Dec 2021 17:12:33 +0530 Subject: [PATCH] Enhanced version ls command to fetch versions in new install --- internal/pkg/cmd/version/functions.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/pkg/cmd/version/functions.go b/internal/pkg/cmd/version/functions.go index c88120f..c9d52ef 100644 --- a/internal/pkg/cmd/version/functions.go +++ b/internal/pkg/cmd/version/functions.go @@ -50,12 +50,34 @@ func versionlsCommand(c *cobra.Command, args []string) error { quiet, _ := c.Root().PersistentFlags().GetBool("quiet") if quiet { versionnames := driver.VersionNames() + + // If no versions available, try to update list + if len(versionnames) == 0 { + err := driver.UpdateVersionList() + if err != nil { + return err + } + + versionnames = driver.VersionNames() + } + for _, versionname := range versionnames { fmt.Println(versionname) } return nil } + driverversions := driver.Versions() + // If no versions available, try to update list + if len(driverversions) == 0 { + err := driver.UpdateVersionList() + if err != nil { + return err + } + + driverversions = driver.Versions() + } + defaultversion, _ := cli.Default("version") var versionlsFormatter = cli.NewTableRenderer( "driverls", @@ -66,7 +88,7 @@ func versionlsCommand(c *cobra.Command, args []string) error { defaultversion, ) - versionlsFormatter.Render(os.Stdout, driver.Versions()) + versionlsFormatter.Render(os.Stdout, driverversions) return nil }