@@ -21,29 +21,29 @@ func initSyncCommand(commonFlags []cli.Flag, clientConfig *types.ClientConfig) *
21
21
Name : "sync" ,
22
22
Usage : "Manage sync operations, scheduled and webhook" ,
23
23
Subcommands : []* cli.Command {
24
- syncCreateCommand (commonFlags , clientConfig ),
24
+ syncScheduleCommand (commonFlags , clientConfig ),
25
25
syncListCommand (commonFlags , clientConfig ),
26
26
syncDeleteCommand (commonFlags , clientConfig ),
27
27
},
28
28
}
29
29
}
30
30
31
- func syncCreateCommand (commonFlags []cli.Flag , clientConfig * types.ClientConfig ) * cli.Command {
31
+ func syncScheduleCommand (commonFlags []cli.Flag , clientConfig * types.ClientConfig ) * cli.Command {
32
32
flags := make ([]cli.Flag , 0 , len (commonFlags )+ 2 )
33
33
flags = append (flags , commonFlags ... )
34
34
flags = append (flags , newStringFlag ("branch" , "b" , "The branch to checkout if using git source" , "main" ))
35
35
flags = append (flags , newStringFlag ("git-auth" , "g" , "The name of the git_auth entry in server config to use" , "" ))
36
36
flags = append (flags , newBoolFlag ("approve" , "a" , "Approve the app permissions" , false ))
37
37
flags = append (flags , newStringFlag ("reload" , "r" , "Which apps to reload: none, updated, matched" , "" ))
38
38
flags = append (flags , newBoolFlag ("promote" , "p" , "Promote changes from stage to prod" , false ))
39
- flags = append (flags , newIntFlag ("schedule " , "s" , "Schedule sync for every N minutes" , 0 ))
39
+ flags = append (flags , newIntFlag ("minutes " , "s" , "Schedule sync for every N minutes" , 0 ))
40
40
flags = append (flags , newBoolFlag ("clobber" , "" , "Force update app config, overwriting non-declarative changes" , false ))
41
- flags = append (flags , newBoolFlag ("force-reload" , "f" , "Force reload even if there is no new commit " , false ))
41
+ flags = append (flags , newBoolFlag ("force-reload" , "f" , "Force reload even if there are no new commits " , false ))
42
42
flags = append (flags , dryRunFlag ())
43
43
44
44
return & cli.Command {
45
- Name : "create " ,
46
- Usage : "Create sync job for updating app config" ,
45
+ Name : "schedule " ,
46
+ Usage : "Create scheduled sync job for updating app config" ,
47
47
Flags : flags ,
48
48
Before : altsrc .InitInputSourceWithContext (flags , altsrc .NewTomlSourceFromFlagFunc (configFileFlagName )),
49
49
ArgsUsage : "<filePath>" ,
@@ -52,23 +52,22 @@ func syncCreateCommand(commonFlags []cli.Flag, clientConfig *types.ClientConfig)
52
52
<filePath> is the path to the apply file containing the app configuration.
53
53
54
54
Examples:
55
- Create sync entry , reloading all apps: clace sync ./app.ace
56
- Create sync entry , reloading updated apps: clace sync --reload=updated github.com/claceio/apps/apps.ace
57
- Create sync entry : clace sync --promote --approve github.com/claceio/apps/apps.ace
58
- Create sync entry , overwriting changes: clace sync --promote --clobber github.com/claceio/apps/apps.ace
55
+ Create scheduled sync , reloading apps with code changes : clace sync schedule ./app.ace
56
+ Create scheduled sync , reloading only apps with a config change : clace sync schedule --reload=updated github.com/claceio/apps/apps.ace
57
+ Create scheduled sync, promoting changes : clace sync schedule --promote --approve github.com/claceio/apps/apps.ace
58
+ Create scheduled sync , overwriting changes: clace sync schedule --promote --clobber github.com/claceio/apps/apps.ace
59
59
` ,
60
-
61
60
Action : func (cCtx * cli.Context ) error {
62
61
if cCtx .NArg () != 1 {
63
62
return fmt .Errorf ("expected one arg : <filePath>" )
64
63
}
65
64
66
65
client := system .NewHttpClient (clientConfig .ServerUri , clientConfig .AdminUser , clientConfig .Client .AdminPassword , clientConfig .Client .SkipCertCheck )
67
66
reloadMode := types .AppReloadOption (cmp .Or (cCtx .String ("reload" ), string (types .AppReloadOptionMatched )))
68
- schedule := cCtx .Int ("schedule" )
69
67
values := url.Values {}
70
68
values .Add ("path" , cCtx .Args ().Get (0 ))
71
69
values .Add (DRY_RUN_ARG , strconv .FormatBool (cCtx .Bool (DRY_RUN_FLAG )))
70
+ values .Add ("scheduled" , "true" )
72
71
73
72
sync := types.SyncMetadata {
74
73
GitBranch : cCtx .String ("branch" ),
@@ -78,7 +77,7 @@ Examples:
78
77
Reload : string (reloadMode ),
79
78
Clobber : cCtx .Bool ("clobber" ),
80
79
ForceReload : cCtx .Bool ("force-reload" ),
81
- ScheduleFrequency : schedule ,
80
+ ScheduleFrequency : cCtx . Int ( "minutes" ) ,
82
81
}
83
82
84
83
var syncResponse types.SyncCreateResponse
@@ -87,8 +86,9 @@ Examples:
87
86
return err
88
87
}
89
88
90
- fmt . Printf ( "Sync job created with Id: %s \n " , syncResponse .Id )
89
+ printApplyResponse ( cCtx , & syncResponse .SyncJobStatus . ApplyResponse )
91
90
91
+ fmt .Printf ("\n Sync job created with Id: %s\n " , syncResponse .Id )
92
92
if syncResponse .DryRun {
93
93
fmt .Print (DRY_RUN_MESSAGE )
94
94
}
@@ -194,30 +194,30 @@ func printSyncList(cCtx *cli.Context, sync []*types.SyncEntry, format string) {
194
194
enc .Encode (s )
195
195
}
196
196
case FORMAT_BASIC :
197
- formatStr := "%-35s %-10s %-40s %-s\n "
198
- fmt .Fprintf (cCtx .App .Writer , formatStr , "Id" , "Trigger " , "Path" , "Url " )
197
+ formatStr := "%-35s %-12s %-s\n "
198
+ fmt .Fprintf (cCtx .App .Writer , formatStr , "Id" , "SyncType " , "Path" )
199
199
200
200
for _ , s := range sync {
201
- fmt .Fprintf (cCtx .App .Writer , formatStr , s .Id , getTriggerType (s ), s .Path , s . Metadata . WebhookUrl )
201
+ fmt .Fprintf (cCtx .App .Writer , formatStr , s .Id , getSyncType (s ), s .Path )
202
202
}
203
203
case FORMAT_TABLE :
204
- formatStrHead := "%-35s %-10s %-8s %-8s %-7s %-6s %-10s %-15s %-40s %-s\n "
205
- formatStrData := "%-35s %-10s %-8s %-8t %-7t %-6t %-10s %-15s %-40s %-s\n "
206
- fmt .Fprintf (cCtx .App .Writer , formatStrHead , "Id" , "Trigger " , "Reload" , "Promote" , "Approve" , "Clobber" , "GitAuth" , "Branch" , "Path" , "Url " )
204
+ formatStrHead := "%-35s %-12s %-8s %-8s %-7s %-7s %-10s %-15s %-s\n "
205
+ formatStrData := "%-35s %-12s %-8s %-8t %-7t %-7t %-10s %-15s %-s\n "
206
+ fmt .Fprintf (cCtx .App .Writer , formatStrHead , "Id" , "SyncType " , "Reload" , "Promote" , "Approve" , "Clobber" , "GitAuth" , "Branch" , "Path" )
207
207
208
208
for _ , s := range sync {
209
- fmt .Fprintf (cCtx .App .Writer , formatStrData , s .Id , getTriggerType (s ), s .Metadata .Reload , s .Metadata .Promote , s .Metadata .Approve , s .Metadata .Clobber , s .Metadata .GitAuth , s .Metadata .GitBranch , s .Path , s . Metadata . WebhookUrl )
209
+ fmt .Fprintf (cCtx .App .Writer , formatStrData , s .Id , getSyncType (s ), s .Metadata .Reload , s .Metadata .Promote , s .Metadata .Approve , s .Metadata .Clobber , s .Metadata .GitAuth , s .Metadata .GitBranch , s .Path )
210
210
}
211
211
case FORMAT_CSV :
212
212
for _ , s := range sync {
213
- fmt .Fprintf (cCtx .App .Writer , "%s,%s,%s,%t,%t,%t,%s,%s,%s,%s\n " , s .Id , getTriggerType (s ), s .Metadata .Reload , s .Metadata .Promote , s .Metadata .Approve , s .Metadata .Clobber , s .Metadata .GitAuth , s .Metadata .GitBranch , s .Path , s .Metadata .WebhookUrl )
213
+ fmt .Fprintf (cCtx .App .Writer , "%s,%s,%s,%t,%t,%t,%s,%s,%s,%s\n " , s .Id , getSyncType (s ), s .Metadata .Reload , s .Metadata .Promote , s .Metadata .Approve , s .Metadata .Clobber , s .Metadata .GitAuth , s .Metadata .GitBranch , s .Path , s .Metadata .WebhookUrl )
214
214
}
215
215
default :
216
216
panic (fmt .Errorf ("unknown format %s" , format ))
217
217
}
218
218
}
219
219
220
- func getTriggerType (sync * types.SyncEntry ) string {
220
+ func getSyncType (sync * types.SyncEntry ) string {
221
221
if sync .Metadata .ScheduleFrequency > 0 {
222
222
return fmt .Sprintf ("%d (mins)" , sync .Metadata .ScheduleFrequency )
223
223
}
0 commit comments