-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcmd_workflows.go
More file actions
668 lines (579 loc) · 20 KB
/
cmd_workflows.go
File metadata and controls
668 lines (579 loc) · 20 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
// SPDX-License-Identifier: Apache-2.0
// Package executor - Workflow SHOW/DESCRIBE commands
package executor
import (
"fmt"
"sort"
"strings"
"github.com/mendixlabs/mxcli/mdl/ast"
"github.com/mendixlabs/mxcli/sdk/workflows"
)
// showWorkflows handles SHOW WORKFLOWS command.
func (e *Executor) showWorkflows(moduleName string) error {
h, err := e.getHierarchy()
if err != nil {
return fmt.Errorf("failed to build hierarchy: %w", err)
}
wfs, err := e.reader.ListWorkflows()
if err != nil {
return fmt.Errorf("failed to list workflows: %w", err)
}
type row struct {
qualifiedName string
module string
name string
activities int
userTasks int
decisions int
paramEntity string
}
var rows []row
for _, wf := range wfs {
modID := h.FindModuleID(wf.ContainerID)
modName := h.GetModuleName(modID)
if moduleName != "" && modName != moduleName {
continue
}
qualifiedName := modName + "." + wf.Name
paramEntity := ""
if wf.Parameter != nil {
paramEntity = wf.Parameter.EntityRef
}
acts, uts, decs := countWorkflowActivities(wf)
rows = append(rows, row{qualifiedName, modName, wf.Name, acts, uts, decs, paramEntity})
}
// Sort by qualified name
sort.Slice(rows, func(i, j int) bool {
return strings.ToLower(rows[i].qualifiedName) < strings.ToLower(rows[j].qualifiedName)
})
result := &TableResult{
Columns: []string{"Qualified Name", "Activities", "User Tasks", "Decisions", "Parameter Entity"},
Summary: fmt.Sprintf("(%d workflows)", len(rows)),
}
for _, r := range rows {
result.Rows = append(result.Rows, []any{r.qualifiedName, r.activities, r.userTasks, r.decisions, r.paramEntity})
}
return e.writeResult(result)
}
// countWorkflowActivities counts total activities, user tasks, and decisions in a workflow.
func countWorkflowActivities(wf *workflows.Workflow) (total, userTasks, decisions int) {
if wf.Flow == nil {
return
}
countFlowActivities(wf.Flow, &total, &userTasks, &decisions)
return
}
// countFlowActivities recursively counts activities in a flow and its sub-flows.
func countFlowActivities(flow *workflows.Flow, total, userTasks, decisions *int) {
if flow == nil {
return
}
for _, act := range flow.Activities {
*total++
switch a := act.(type) {
case *workflows.UserTask:
*userTasks++
for _, outcome := range a.Outcomes {
countFlowActivities(outcome.Flow, total, userTasks, decisions)
}
case *workflows.ExclusiveSplitActivity:
*decisions++
for _, outcome := range a.Outcomes {
if co, ok := outcome.(*workflows.BooleanConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.EnumerationValueConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.VoidConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
}
}
case *workflows.ParallelSplitActivity:
for _, outcome := range a.Outcomes {
countFlowActivities(outcome.Flow, total, userTasks, decisions)
}
case *workflows.CallMicroflowTask:
for _, outcome := range a.Outcomes {
if co, ok := outcome.(*workflows.BooleanConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.EnumerationValueConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.VoidConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
}
}
case *workflows.SystemTask:
for _, outcome := range a.Outcomes {
if co, ok := outcome.(*workflows.BooleanConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.EnumerationValueConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
} else if co, ok := outcome.(*workflows.VoidConditionOutcome); ok {
countFlowActivities(co.Flow, total, userTasks, decisions)
}
}
}
}
}
// describeWorkflow handles DESCRIBE WORKFLOW command.
func (e *Executor) describeWorkflow(name ast.QualifiedName) error {
output, _, err := e.describeWorkflowToString(name)
if err != nil {
return err
}
fmt.Fprintln(e.output, output)
return nil
}
// describeWorkflowToString generates MDL-like output for a workflow and returns it as a string.
func (e *Executor) describeWorkflowToString(name ast.QualifiedName) (string, map[string]elkSourceRange, error) {
h, err := e.getHierarchy()
if err != nil {
return "", nil, fmt.Errorf("failed to build hierarchy: %w", err)
}
allWorkflows, err := e.reader.ListWorkflows()
if err != nil {
return "", nil, fmt.Errorf("failed to list workflows: %w", err)
}
var targetWf *workflows.Workflow
for _, wf := range allWorkflows {
modID := h.FindModuleID(wf.ContainerID)
modName := h.GetModuleName(modID)
if modName == name.Module && wf.Name == name.Name {
targetWf = wf
break
}
}
if targetWf == nil {
return "", nil, fmt.Errorf("workflow not found: %s", name)
}
var lines []string
qualifiedName := name.Module + "." + name.Name
// Documentation
if targetWf.Documentation != "" {
lines = append(lines, "/**")
for docLine := range strings.SplitSeq(targetWf.Documentation, "\n") {
lines = append(lines, " * "+docLine)
}
lines = append(lines, " */")
}
// Header
lines = append(lines, fmt.Sprintf("-- Workflow: %s", qualifiedName))
if targetWf.Annotation != "" {
lines = append(lines, fmt.Sprintf("-- %s", targetWf.Annotation))
}
lines = append(lines, "")
lines = append(lines, fmt.Sprintf("WORKFLOW %s", qualifiedName))
// Context parameter
if targetWf.Parameter != nil && targetWf.Parameter.EntityRef != "" {
lines = append(lines, fmt.Sprintf(" PARAMETER $WorkflowContext: %s", targetWf.Parameter.EntityRef))
}
// Display name
if targetWf.WorkflowName != "" {
escaped := strings.ReplaceAll(targetWf.WorkflowName, "'", "''")
lines = append(lines, fmt.Sprintf(" DISPLAY '%s'", escaped))
}
// Description
if targetWf.WorkflowDescription != "" {
escaped := strings.ReplaceAll(targetWf.WorkflowDescription, "'", "''")
lines = append(lines, fmt.Sprintf(" DESCRIPTION '%s'", escaped))
}
// Export level (only emit when non-empty)
if targetWf.ExportLevel != "" {
lines = append(lines, fmt.Sprintf(" EXPORT LEVEL %s", targetWf.ExportLevel))
}
// Overview page
if targetWf.OverviewPage != "" {
lines = append(lines, fmt.Sprintf(" OVERVIEW PAGE %s", targetWf.OverviewPage))
}
// Due date
if targetWf.DueDate != "" {
lines = append(lines, fmt.Sprintf(" DUE DATE '%s'", targetWf.DueDate))
}
lines = append(lines, "")
lines = append(lines, "BEGIN")
// Activities
if targetWf.Flow != nil {
actLines := formatWorkflowActivities(targetWf.Flow, " ")
lines = append(lines, actLines...)
}
lines = append(lines, "END WORKFLOW")
lines = append(lines, "/")
return strings.Join(lines, "\n"), nil, nil
}
// formatAnnotation returns an ANNOTATION statement for a workflow activity annotation.
// The annotation is emitted as a parseable MDL statement so it survives round-trips.
func formatAnnotation(annotation string, indent string) string {
if annotation == "" {
return ""
}
escaped := strings.ReplaceAll(annotation, "'", "''")
return fmt.Sprintf("%sANNOTATION '%s';", indent, escaped)
}
// boundaryEventKeyword maps an EventType string to the MDL BOUNDARY EVENT keyword sequence.
func boundaryEventKeyword(eventType string) string {
switch eventType {
case "InterruptingTimer":
return "BOUNDARY EVENT INTERRUPTING TIMER"
case "NonInterruptingTimer":
return "BOUNDARY EVENT NON INTERRUPTING TIMER"
default:
return "BOUNDARY EVENT TIMER"
}
}
// formatBoundaryEvents formats boundary events for describe output.
func formatBoundaryEvents(events []*workflows.BoundaryEvent, indent string) []string {
if len(events) == 0 {
return nil
}
var lines []string
for _, event := range events {
keyword := boundaryEventKeyword(event.EventType)
if event.TimerDelay != "" {
escapedDelay := strings.ReplaceAll(event.TimerDelay, "'", "''")
lines = append(lines, fmt.Sprintf("%s%s '%s'", indent, keyword, escapedDelay))
} else {
lines = append(lines, fmt.Sprintf("%s%s", indent, keyword))
}
if event.Flow != nil && len(event.Flow.Activities) > 0 {
lines = append(lines, fmt.Sprintf("%s{", indent))
subLines := formatWorkflowActivities(event.Flow, indent+" ")
lines = append(lines, subLines...)
lines = append(lines, fmt.Sprintf("%s}", indent))
}
}
return lines
}
// formatWorkflowActivities generates MDL-like output for workflow activities.
func formatWorkflowActivities(flow *workflows.Flow, indent string) []string {
if flow == nil {
return nil
}
var lines []string
for _, act := range flow.Activities {
var actLines []string
isComment := false
switch a := act.(type) {
case *workflows.UserTask:
actLines = formatUserTask(a, indent)
case *workflows.CallMicroflowTask:
actLines = formatCallMicroflowTask(a, indent)
case *workflows.SystemTask:
actLines = formatSystemTask(a, indent)
case *workflows.CallWorkflowActivity:
actLines = formatCallWorkflowActivity(a, indent)
case *workflows.ExclusiveSplitActivity:
actLines = formatExclusiveSplit(a, indent)
case *workflows.ParallelSplitActivity:
actLines = formatParallelSplit(a, indent)
case *workflows.JumpToActivity:
target := a.TargetActivity
if target == "" {
target = "?"
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
if a.Annotation != "" {
actLines = append(actLines, formatAnnotation(a.Annotation, indent))
}
escapedCaption := strings.ReplaceAll(caption, "'", "''")
actLines = append(actLines, fmt.Sprintf("%sJUMP TO %s COMMENT '%s'", indent, target, escapedCaption))
case *workflows.WaitForTimerActivity:
caption := a.Caption
if caption == "" {
caption = a.Name
}
if a.Annotation != "" {
actLines = append(actLines, formatAnnotation(a.Annotation, indent))
}
if a.DelayExpression != "" {
escapedDelay := strings.ReplaceAll(a.DelayExpression, "'", "''")
escapedCaption := strings.ReplaceAll(caption, "'", "''")
actLines = append(actLines, fmt.Sprintf("%sWAIT FOR TIMER '%s' COMMENT '%s'", indent, escapedDelay, escapedCaption))
} else {
escapedCaption := strings.ReplaceAll(caption, "'", "''")
actLines = append(actLines, fmt.Sprintf("%sWAIT FOR TIMER COMMENT '%s'", indent, escapedCaption))
}
case *workflows.WaitForNotificationActivity:
caption := a.Caption
if caption == "" {
caption = a.Name
}
if a.Annotation != "" {
actLines = append(actLines, formatAnnotation(a.Annotation, indent))
}
actLines = append(actLines, fmt.Sprintf("%sWAIT FOR NOTIFICATION -- %s", indent, caption))
// BoundaryEvents
actLines = append(actLines, formatBoundaryEvents(a.BoundaryEvents, indent+" ")...)
case *workflows.StartWorkflowActivity:
// Skip start activities - they are implicit
continue
case *workflows.EndWorkflowActivity:
// Skip end activities - they are implicit
continue
case *workflows.EndOfParallelSplitPathActivity:
// Skip - auto-generated by Mendix, implicit in MDL syntax
continue
case *workflows.EndOfBoundaryEventPathActivity:
// Skip - auto-generated by Mendix, implicit in MDL syntax
continue
case *workflows.WorkflowAnnotationActivity:
// Standalone annotation (sticky note) - emit as ANNOTATION statement
if a.Description != "" {
escapedDesc := strings.ReplaceAll(a.Description, "'", "''")
actLines = []string{fmt.Sprintf("%sANNOTATION '%s'", indent, escapedDesc)}
} else {
continue
}
case *workflows.GenericWorkflowActivity:
isComment = true
caption := a.Caption
if caption == "" {
caption = a.Name
}
actLines = []string{fmt.Sprintf("%s-- [%s] %s", indent, a.TypeString, caption)}
default:
isComment = true
actLines = []string{fmt.Sprintf("%s-- [unknown activity]", indent)}
}
// Append semicolon to last line of activity (not for comments)
// Insert before any -- comment to avoid the comment swallowing the semicolon
if !isComment && len(actLines) > 0 {
lastLine := actLines[len(actLines)-1]
if idx := strings.Index(lastLine, " -- "); idx >= 0 {
actLines[len(actLines)-1] = lastLine[:idx] + ";" + lastLine[idx:]
} else {
actLines[len(actLines)-1] = lastLine + ";"
}
}
lines = append(lines, actLines...)
lines = append(lines, "")
}
return lines
}
// formatUserTask formats a user task for describe output.
func formatUserTask(a *workflows.UserTask, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
nameStr := a.Name
if nameStr == "" {
nameStr = "unnamed"
}
taskKeyword := "USER TASK"
if a.IsMulti {
taskKeyword = "MULTI USER TASK"
}
lines = append(lines, fmt.Sprintf("%s%s %s '%s'", indent, taskKeyword, nameStr, caption))
if a.Page != "" {
lines = append(lines, fmt.Sprintf("%s PAGE %s", indent, a.Page))
}
// User targeting
if a.UserSource != nil {
switch us := a.UserSource.(type) {
case *workflows.MicroflowBasedUserSource:
if us.Microflow != "" {
lines = append(lines, fmt.Sprintf("%s TARGETING MICROFLOW %s", indent, us.Microflow))
}
case *workflows.XPathBasedUserSource:
if us.XPath != "" {
lines = append(lines, fmt.Sprintf("%s TARGETING XPATH '%s'", indent, us.XPath))
}
case *workflows.MicroflowGroupSource:
if us.Microflow != "" {
lines = append(lines, fmt.Sprintf("%s TARGETING GROUPS MICROFLOW %s", indent, us.Microflow))
}
case *workflows.XPathGroupSource:
if us.XPath != "" {
lines = append(lines, fmt.Sprintf("%s TARGETING GROUPS XPATH '%s'", indent, us.XPath))
}
}
}
if a.UserTaskEntity != "" {
lines = append(lines, fmt.Sprintf("%s ENTITY %s", indent, a.UserTaskEntity))
}
// Due date (task-level)
if a.DueDate != "" {
escapedDueDate := strings.ReplaceAll(a.DueDate, "'", "''")
lines = append(lines, fmt.Sprintf("%s DUE DATE '%s'", indent, escapedDueDate))
}
// Task description
if a.TaskDescription != "" {
escaped := strings.ReplaceAll(a.TaskDescription, "'", "''")
lines = append(lines, fmt.Sprintf("%s DESCRIPTION '%s'", indent, escaped))
}
// Outcomes
if len(a.Outcomes) > 0 {
lines = append(lines, fmt.Sprintf("%s OUTCOMES", indent))
for _, outcome := range a.Outcomes {
outValue := outcome.Value
if outValue == "" {
outValue = outcome.Caption
}
if outValue == "" {
outValue = outcome.Name
}
if outcome.Flow != nil && len(outcome.Flow.Activities) > 0 {
lines = append(lines, fmt.Sprintf("%s '%s' {", indent, outValue))
subLines := formatWorkflowActivities(outcome.Flow, indent+" ")
lines = append(lines, subLines...)
lines = append(lines, fmt.Sprintf("%s }", indent))
} else {
lines = append(lines, fmt.Sprintf("%s '%s' { }", indent, outValue))
}
}
}
// BoundaryEvents
lines = append(lines, formatBoundaryEvents(a.BoundaryEvents, indent+" ")...)
return lines
}
// formatCallMicroflowTask formats a call microflow task for describe output.
func formatCallMicroflowTask(a *workflows.CallMicroflowTask, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
mf := a.Microflow
if mf == "" {
mf = "?"
}
if len(a.ParameterMappings) > 0 {
var params []string
for _, pm := range a.ParameterMappings {
paramName := pm.Parameter
if idx := strings.LastIndex(paramName, "."); idx >= 0 {
paramName = paramName[idx+1:]
}
params = append(params, fmt.Sprintf("%s = '%s'", paramName, strings.ReplaceAll(pm.Expression, "'", "''")))
}
lines = append(lines, fmt.Sprintf("%sCALL MICROFLOW %s WITH (%s) -- %s", indent, mf, strings.Join(params, ", "), caption))
} else {
lines = append(lines, fmt.Sprintf("%sCALL MICROFLOW %s -- %s", indent, mf, caption))
}
// BoundaryEvents
lines = append(lines, formatBoundaryEvents(a.BoundaryEvents, indent+" ")...)
// Outcomes
lines = append(lines, formatConditionOutcomes(a.Outcomes, indent)...)
return lines
}
// formatSystemTask formats a system task for describe output.
func formatSystemTask(a *workflows.SystemTask, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
mf := a.Microflow
if mf == "" {
mf = "?"
}
lines = append(lines, fmt.Sprintf("%sCALL MICROFLOW %s -- %s", indent, mf, caption))
// Outcomes
lines = append(lines, formatConditionOutcomes(a.Outcomes, indent)...)
return lines
}
// formatCallWorkflowActivity formats a call workflow activity for describe output.
func formatCallWorkflowActivity(a *workflows.CallWorkflowActivity, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
wf := a.Workflow
if wf == "" {
wf = "?"
}
escapedCaption := strings.ReplaceAll(caption, "'", "''")
if len(a.ParameterMappings) > 0 {
var params []string
for _, pm := range a.ParameterMappings {
paramName := pm.Parameter
if idx := strings.LastIndex(paramName, "."); idx >= 0 {
paramName = paramName[idx+1:]
}
params = append(params, fmt.Sprintf("%s = '%s'", paramName, strings.ReplaceAll(pm.Expression, "'", "''")))
}
lines = append(lines, fmt.Sprintf("%sCALL WORKFLOW %s COMMENT '%s' WITH (%s)", indent, wf, escapedCaption, strings.Join(params, ", ")))
} else {
lines = append(lines, fmt.Sprintf("%sCALL WORKFLOW %s COMMENT '%s'", indent, wf, escapedCaption))
}
// BoundaryEvents
lines = append(lines, formatBoundaryEvents(a.BoundaryEvents, indent+" ")...)
return lines
}
// formatExclusiveSplit formats an exclusive split (decision) for describe output.
func formatExclusiveSplit(a *workflows.ExclusiveSplitActivity, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
if a.Expression != "" {
escapedExpr := strings.ReplaceAll(a.Expression, "'", "''")
lines = append(lines, fmt.Sprintf("%sDECISION '%s' -- %s", indent, escapedExpr, caption))
} else {
lines = append(lines, fmt.Sprintf("%sDECISION -- %s", indent, caption))
}
lines = append(lines, formatConditionOutcomes(a.Outcomes, indent)...)
return lines
}
// formatParallelSplit formats a parallel split for describe output.
func formatParallelSplit(a *workflows.ParallelSplitActivity, indent string) []string {
var lines []string
if a.Annotation != "" {
lines = append(lines, formatAnnotation(a.Annotation, indent))
}
caption := a.Caption
if caption == "" {
caption = a.Name
}
lines = append(lines, fmt.Sprintf("%sPARALLEL SPLIT -- %s", indent, caption))
for i, outcome := range a.Outcomes {
lines = append(lines, fmt.Sprintf("%s PATH %d {", indent, i+1))
if outcome.Flow != nil && len(outcome.Flow.Activities) > 0 {
subLines := formatWorkflowActivities(outcome.Flow, indent+" ")
lines = append(lines, subLines...)
}
lines = append(lines, fmt.Sprintf("%s }", indent))
}
return lines
}
// formatConditionOutcomes formats condition outcomes for describe output.
func formatConditionOutcomes(outcomes []workflows.ConditionOutcome, indent string) []string {
if len(outcomes) == 0 {
return nil
}
var lines []string
lines = append(lines, fmt.Sprintf("%s OUTCOMES", indent))
for _, outcome := range outcomes {
name := outcome.GetName()
flow := outcome.GetFlow()
if flow != nil && len(flow.Activities) > 0 {
lines = append(lines, fmt.Sprintf("%s %s -> {", indent, name))
subLines := formatWorkflowActivities(flow, indent+" ")
lines = append(lines, subLines...)
lines = append(lines, fmt.Sprintf("%s }", indent))
} else {
lines = append(lines, fmt.Sprintf("%s %s -> { }", indent, name))
}
}
return lines
}