Skip to content

Commit

Permalink
✨ Allow installing specific provider versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavgerchev committed Sep 25, 2023
1 parent 2495c14 commit 56f45fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 16 additions & 0 deletions apps/cnquery/cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -51,9 +52,17 @@ var listProvidersCmd = &cobra.Command{
var installProviderCmd = &cobra.Command{
Use: "install <NAME>",
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")
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down

0 comments on commit 56f45fd

Please sign in to comment.