MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / findMaxCommonVersion

Function findMaxCommonVersion

cli/cmd/sync.go:111–140  ·  view source on GitHub ↗

findMaxCommonVersion finds the max common version between protocol versions supported by a plugin and those supported by the CLI. If all plugin versions are lower than min CLI supported version, it returns -1. If all plugin versions are higher than max CLI supported version, it returns -2. In this w

(pluginSupported []int, cliSupported []int)

Source from the content-addressed store, hash-verified

109// if -1, the source needs to be updated or the CLI downgraded;
110// if -2, the CLI needs to be updated or the source downgraded.
111func findMaxCommonVersion(pluginSupported []int, cliSupported []int) int {
112 if len(pluginSupported) == 0 {
113 return -1
114 }
115
116 minCLISupported, maxCLISupported := math.MaxInt32, -1
117 for _, v := range cliSupported {
118 if v < minCLISupported {
119 minCLISupported = v
120 }
121 if v > maxCLISupported {
122 maxCLISupported = v
123 }
124 }
125
126 minVersion := math.MaxInt32
127 maxCommon := -1
128 for _, v := range pluginSupported {
129 if v < minVersion {
130 minVersion = v
131 }
132 if v > maxCommon && slices.Contains(cliSupported, v) {
133 maxCommon = v
134 }
135 }
136 if maxCommon == -1 && minVersion > maxCLISupported {
137 return -2
138 }
139 return maxCommon
140}
141
142func parseShard(cmd *cobra.Command) (*shard, error) {
143 shardFlag, err := cmd.Flags().GetString("shard")

Callers 4

syncFunction · 0.85
migrateFunction · 0.85
tablesFunction · 0.85
TestFindMaxCommonVersionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFindMaxCommonVersionFunction · 0.68