-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcommon-flags.go
More file actions
116 lines (106 loc) · 3.01 KB
/
common-flags.go
File metadata and controls
116 lines (106 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (C) 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package flags
import (
"flag"
"strings"
)
const (
ALL = "ALL" // All modules
DEFAULT = "DEFAULT" // Modules other than those excluded
KAFKA = "KAFKA"
SPANNER = "SPANNER"
BIGTABLE = "BIGTABLE"
DATASTREAM = "DATASTREAM"
)
// Avoid making these vars public.
var (
modulesToBuild string
moduleMap = map[string][]string{
ALL: {},
DEFAULT: {},
KAFKA: {"v2/kafka-common/",
"v2/kafka-to-bigquery/",
"v2/kafka-to-gcs/",
"v2/kafka-to-kafka/",
"v2/kafka-to-pubsub/",
"v2/pubsub-to-kafka/",
"plugins/templates-maven-plugin",
},
SPANNER: {"v2/datastream-to-spanner/",
"v2/spanner-change-streams-to-sharded-file-sink/",
"v2/gcs-to-sourcedb/",
"v2/sourcedb-to-spanner/",
"v2/spanner-to-sourcedb/",
"v2/spanner-custom-shard/",
"plugins/templates-maven-plugin"},
BIGTABLE: {"v2/bigtable-common/",
"v2/bigquery-to-bigtable/",
"v2/bigtable-changestreams-to-hbase/",
"plugins/templates-maven-plugin",
},
DATASTREAM: {
"plugins/templates-maven-plugin",
"v2/datastream-common/",
"v2/datastream-mongodb-to-firestore/",
"v2/datastream-to-bigquery/",
"v2/datastream-to-mongodb/",
"v2/datastream-to-postgres/",
"v2/datastream-to-sql/",
},
}
// New map for short name to full path mapping
shortNameToFullPathMap = map[string]string{
"spanner-to-sourcedb": "v2/spanner-to-sourcedb/",
// Add other mappings as needed
}
)
// Registers all common flags. Must be called before flag.Parse().
func RegisterCommonFlags() {
flag.StringVar(&modulesToBuild, "modules-to-build", ALL, "List of modules to build/run commands against")
}
// SetModulesToBuild allows setting the modules to build programmatically.
func SetModulesToBuild(module string) {
modulesToBuild = module
}
// Returns all modules to build.
func ModulesToBuild() []string {
m := modulesToBuild
// Check if the module is a short name
if fullPath, ok := shortNameToFullPathMap[m]; ok {
return []string{fullPath}
}
if m == "DEFAULT" {
// "DEFAULT" is "ALL" minus other modules defined in moduleMap
var s []string
for k, v := range moduleMap {
if k != "ALL" && k != "DEFAULT" {
for _, n := range v {
if !(strings.HasPrefix(n, "plugins/") || strings.Contains(n, "common/")) {
s = append(s, "!"+n)
}
}
}
}
return s
} else if val, ok := moduleMap[modulesToBuild]; ok {
return val
}
if len(m) == 0 {
return make([]string, 0)
}
return strings.Split(m, ",")
}