@@ -14,8 +14,9 @@ import (
1414)
1515
1616var (
17- reformat = artifact_command .Command ("reformat" , "Reformat a set of artifacts" )
18- reformat_args = reformat .Arg ("paths" , "Paths to artifact yaml files" ).Required ().Strings ()
17+ reformat = artifact_command .Command ("reformat" , "Reformat a set of artifacts" )
18+ reformat_dry_run = reformat .Flag ("dry" , "Do not overwrite files, just report errors" ).Bool ()
19+ reformat_args = reformat .Arg ("paths" , "Paths to artifact yaml files" ).Required ().Strings ()
1920)
2021
2122func doReformat () error {
@@ -58,41 +59,25 @@ func doReformat() error {
5859 ACLManager : acl_managers .NewRoleACLManager (sm .Config , "administrator" ),
5960 Logger : log .New (artifact_logger , "" , 0 ),
6061 Env : ordereddict .NewDict ().
62+ Set ("DryRun" , * reformat_dry_run ).
6163 Set ("Artifacts" , artifact_paths ),
6264 }
6365
6466 query := `
65- LET Results <= SELECT FilePath,
66- Result
67- FROM foreach(row=Artifacts,
68- query={
69- SELECT _value AS FilePath,
70- reformat(artifact=read_file(filename=_value)) AS Result
71- FROM scope()
72- })
73-
74- LET Errors <= SELECT *
75- FROM foreach(row=Results,
76- query={
77- SELECT log(level="ERROR", message="%s: %s", args=[FilePath, Result.Error])
78- FROM scope()
79- WHERE Result.Error
80- })
81-
82- SELECT *
83- FROM foreach(row=Results,
84- query={
85- SELECT FilePath,
86- Result.Artifact AS Artifact,
87- Result.Error AS Error,
88- if(condition=NOT Result.Error,
89- then=copy(filename=Result.Artifact,
90- accessor="data",
91- dest=FilePath)) AS _Copy
92- FROM scope()
93- })
94- `
95-
67+ LET Reformatted = SELECT reformat(artifact=read_file(filename=_value)) AS Result
68+ FROM foreach(row=Artifacts)
69+ WHERE if(condition=Result.Error,
70+ then=log(level="ERROR", message="%v: <red>%v</>",
71+ args=[_value, Result.Error], dedup=-1),
72+ else=log(message="Reformatted %v: <green>OK</>",
73+ args=_value, dedup=-1)
74+ AND NOT DryRun
75+ AND copy(accessor="data", dest=_value, filename=Result.Artifact))
76+ AND FALSE
77+
78+ SELECT * FROM Reformatted
79+
80+ `
9681 err = runQueryWithEnv (query , builder , "json" )
9782 if err != nil {
9883 logger .Error ("reformat: error running query: %v" , query )
0 commit comments