diff --git a/apps/cnquery/cmd/providers.go b/apps/cnquery/cmd/providers.go index 9272128e22..2e2a7ed2db 100644 --- a/apps/cnquery/cmd/providers.go +++ b/apps/cnquery/cmd/providers.go @@ -26,6 +26,7 @@ func init() { installProviderCmd.Flags().StringP("file", "f", "", "install a provider via a file") installProviderCmd.Flags().String("url", "", "install a provider via URL") + installProviderCmd.Flags().String("version", "", "install a specific version of a provider") } var ProvidersCmd = &cobra.Command{ @@ -51,9 +52,17 @@ var listProvidersCmd = &cobra.Command{ var installProviderCmd = &cobra.Command{ Use: "install ", Short: "Install or update a provider.", + Args: cobra.MinimumNArgs(1), Long: "", PreRun: func(cmd *cobra.Command, args []string) {}, Run: func(cmd *cobra.Command, args []string) { + // If there's a version and a name, we can install the version, using the default home url for + // providers + version, _ := cmd.Flags().GetString("version") + if version != "" { + installProviderByVersion(args[0], version) + return + } // Explicit installs of files will ignore version recommendations. // So we just take them and roll with it. path, _ := cmd.Flags().GetString("file") @@ -72,6 +81,13 @@ var installProviderCmd = &cobra.Command{ }, } +func installProviderByVersion(name string, version string) { + _, err := providers.Install(name, version) + if err != nil { + log.Fatal().Err(err).Msg("failed to install") + } +} + func installProviderUrl(u string) { if i := strings.Index(u, "://"); i == -1 { u = "http://" + u diff --git a/providers/providers.go b/providers/providers.go index 3784e24d49..a74963428b 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -175,15 +175,18 @@ func EnsureProvider(existing Providers, connectorName string, connectorType stri return nil, errors.New("cannot find installed provider for connection " + connectorName) } - nu, err := Install(upstream.Name) + nu, err := Install(upstream.Name, "") existing.Add(nu) return nu, err } -func Install(name string) (*Provider, error) { - version, err := LatestVersion(name) - if err != nil { - return nil, err +func Install(name string, version string) (*Provider, error) { + if version == "" { + latestVersion, err := LatestVersion(name) + if err != nil { + return nil, err + } + version = latestVersion } log.Info().