@@ -38,24 +38,37 @@ Tidy object metadata.
38
38
* picklist fields missing from Record Types
39
39
` ,
40
40
Args : cobra .MinimumNArgs (1 ),
41
- Run : func (cmd * cobra.Command , args []string ) {
41
+ RunE : func (cmd * cobra.Command , args []string ) error {
42
42
changes := false
43
+ list , _ := cmd .Flags ().GetBool ("list" )
44
+ fixMissing , _ := cmd .Flags ().GetBool ("fix-missing" )
45
+ fix := fixes {
46
+ recordTypePicklistOptions : fixMissing ,
47
+ }
43
48
for _ , file := range args {
44
- list , _ := cmd .Flags ().GetBool ("list" )
45
- fixMissing , _ := cmd .Flags ().GetBool ("fix-missing" )
46
- fix := fixes {
47
- recordTypePicklistOptions : fixMissing ,
49
+ _ , err := internal .Metadata .Open (file )
50
+ if err != nil {
51
+ return fmt .Errorf ("invalid file %s: %w" , file , err )
48
52
}
53
+ }
54
+
55
+ items := internal .Metadata .Items (objects .NAME )
56
+ if len (items ) == 0 {
57
+ log .Warn ("No objects to tidy" )
58
+ }
59
+ for _ , item := range items {
60
+ o := item .(* objects.CustomObject )
49
61
if list {
50
- needsTidying := checkIfChanged (file , fix )
62
+ needsTidying := checkIfChanged (o , fix )
51
63
changes = needsTidying || changes
52
64
} else {
53
- tidy (file , fix )
65
+ tidy (o , fix )
54
66
}
55
67
}
56
68
if changes {
57
69
os .Exit (1 )
58
70
}
71
+ return nil
59
72
},
60
73
}
61
74
@@ -153,13 +166,8 @@ func addMissingRecordTypePicklistFields(o *objects.CustomObject) {
153
166
}
154
167
}
155
168
156
- func checkIfChanged (file string , fix fixes ) (changed bool ) {
157
- o := & objects.CustomObject {}
158
- contents , err := internal .ParseMetadataXmlIfPossible (o , file )
159
- if err != nil {
160
- log .Warn ("parse failure:" + err .Error ())
161
- return
162
- }
169
+ func checkIfChanged (o * objects.CustomObject , fix fixes ) (changed bool ) {
170
+ contents := o .Contents ()
163
171
if fix .recordTypePicklistOptions {
164
172
addMissingRecordTypePicklistFields (o )
165
173
}
@@ -173,25 +181,20 @@ func checkIfChanged(file string, fix fixes) (changed bool) {
173
181
return
174
182
}
175
183
if ! bytes .Equal (contents , newContents ) {
176
- fmt .Println (file )
184
+ fmt .Println (o . Path () )
177
185
return true
178
186
}
179
187
return false
180
188
}
181
189
182
- func tidy (file string , fix fixes ) {
183
- p , err := objects .Open (file )
184
- if err != nil {
185
- log .Warn ("parsing object failed: " + err .Error ())
186
- return
187
- }
190
+ func tidy (o * objects.CustomObject , fix fixes ) {
188
191
if warn {
189
- checkUnassignedPicklistOptions (p )
192
+ checkUnassignedPicklistOptions (o )
190
193
}
191
194
if fix .recordTypePicklistOptions {
192
- addMissingRecordTypePicklistFields (p )
195
+ addMissingRecordTypePicklistFields (o )
193
196
}
194
- if err := general .Tidy (p , file ); err != nil {
197
+ if err := general .Tidy (o , o . Path () ); err != nil {
195
198
log .Warn ("tidying failed: " + err .Error ())
196
199
}
197
200
}
0 commit comments