Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement: atmos list workflows #941

Merged
merged 27 commits into from
Jan 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
514acfb
fix: suppress config error when help is requested
Cerebrovinny Jan 17, 2025
e4ebc35
feat: add list configuration to workflows schema
Cerebrovinny Jan 14, 2025
99e154c
feat: add list workflows command to display Atmos workflows
Cerebrovinny Jan 14, 2025
c31c03a
feat: add workflow listing functionality with table output support
Cerebrovinny Jan 15, 2025
8a30e04
Add tests for workflow listing functionality
Cerebrovinny Jan 15, 2025
c6bf17d
fix: add newline at the end of workflow list output
Cerebrovinny Jan 15, 2025
665d403
refactor: use CheckTTYSupport for terminal detection
Cerebrovinny Jan 16, 2025
1425b8e
refactor: use theme styles for workflow list table formatting
Cerebrovinny Jan 16, 2025
6e26a8f
feat(workflows): add file loading and parsing functionality for workf…
Cerebrovinny Jan 16, 2025
df3d8f9
test(list): enhance workflow listing test coverage with temporary files
Cerebrovinny Jan 16, 2025
9ec99ab
feat(workflows): add JSON and CSV output formats for workflow listing
Cerebrovinny Jan 16, 2025
9648e08
fixes log level
Cerebrovinny Jan 19, 2025
eb95d39
update cli tests
Cerebrovinny Jan 20, 2025
d2fc75e
fix: use OS-specific line endings in workflow list output
Cerebrovinny Jan 20, 2025
51da66f
feat: add OS-specific line ending support and format validation tests
Cerebrovinny Jan 20, 2025
ad5d75f
feat: add format validation for workflow list output
Cerebrovinny Jan 20, 2025
a7b317f
feat: add file path validation and handle nil workflows in manifest
Cerebrovinny Jan 20, 2025
f9a2431
refactor: move line ending logic to utils package
Cerebrovinny Jan 21, 2025
809a76a
Add test snapshots for log level validation and CLI command output
Cerebrovinny Jan 21, 2025
2210ce7
Enable snapshots and add diff validation for log level tests
Cerebrovinny Jan 21, 2025
c02b97d
feat: add GetLineEnding function to handle platform-specific line end…
Cerebrovinny Jan 21, 2025
d566118
refactor: use runtime.GOOS to detect Windows platform for line endings
Cerebrovinny Jan 21, 2025
a8130b9
update copy
Cerebrovinny Jan 21, 2025
50cd2db
fix expected diff
Cerebrovinny Jan 21, 2025
bf14e63
feat: implement workflow discovery from configured workflow directory
Cerebrovinny Jan 22, 2025
c8e10c1
Remove alternating row styles in workflow list
Cerebrovinny Jan 24, 2025
6b0797b
Merge branch 'main' into DEV-2801
aknysh Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add workflow listing functionality with table output support
  • Loading branch information
Cerebrovinny committed Jan 24, 2025
commit c31c03af6f844d1c5d2445d1619d242e38b59301
119 changes: 119 additions & 0 deletions pkg/list/list_workflows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package list

import (
"fmt"
"os"
"sort"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/samber/lo"
"golang.org/x/term"

"github.com/cloudposse/atmos/pkg/schema"
)

// getWorkflowsFromManifest extracts workflows from a workflow manifest
func getWorkflowsFromManifest(manifest schema.WorkflowManifest) ([][]string, error) {
var rows [][]string
for workflowName, workflow := range manifest.Workflows {
rows = append(rows, []string{
manifest.Name,
workflowName,
workflow.Description,
})
}
return rows, nil
}

// FilterAndListWorkflows filters and lists workflows based on the given file
func FilterAndListWorkflows(fileFlag string, listConfig schema.ListConfig) (string, error) {
// Parse columns configuration
header := []string{"File", "Workflow", "Description"}

// Get all workflows from manifests
var rows [][]string

// TODO: Implement actual workflow manifest loading logic
// For now using example data
manifest := schema.WorkflowManifest{
Name: "example",
Workflows: schema.WorkflowConfig{
"test-1": schema.WorkflowDefinition{
Description: "Test workflow",
Steps: []schema.WorkflowStep{
{Command: "echo Command 1", Name: "step1", Type: "shell"},
{Command: "echo Command 2", Name: "step2", Type: "shell"},
{Command: "echo Command 3", Name: "step3", Type: "shell"},
{Command: "echo Command 4", Type: "shell"},
},
},
},
}

manifestRows, err := getWorkflowsFromManifest(manifest)
if err != nil {
return "", fmt.Errorf("error processing manifest: %w", err)
}
rows = append(rows, manifestRows...)

// Remove duplicates and sort
rows = lo.UniqBy(rows, func(row []string) string {
return strings.Join(row, "\t")
})
sort.Slice(rows, func(i, j int) bool {
return strings.Join(rows[i], "\t") < strings.Join(rows[j], "\t")
})
Cerebrovinny marked this conversation as resolved.
Show resolved Hide resolved

if len(rows) == 0 {
return "No workflows found", nil
}

// Calculate column widths
colWidths := make([]int, len(header))
for i, h := range header {
colWidths[i] = len(h)
}
for _, row := range rows {
for i, field := range row {
if len(field) > colWidths[i] {
colWidths[i] = len(field)
}
}
}

// Check if TTY is attached
if !term.IsTerminal(int(os.Stdout.Fd())) {
Cerebrovinny marked this conversation as resolved.
Show resolved Hide resolved
// Degrade to simple tabular format
var output strings.Builder
output.WriteString(strings.Join(header, "\t") + "\n")
for _, row := range rows {
output.WriteString(strings.Join(row, "\t") + "\n")
}
return output.String(), nil
}

// Create a styled table
t := table.New().
Border(lipgloss.ThickBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("241"))).
StyleFunc(func(row, col int) lipgloss.Style {
if row == 0 {
return lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("99")).
Align(lipgloss.Center)
}
if row%2 == 0 {
return lipgloss.NewStyle().
Foreground(lipgloss.Color("245"))
}
return lipgloss.NewStyle().
Foreground(lipgloss.Color("241"))
}).
Cerebrovinny marked this conversation as resolved.
Show resolved Hide resolved
Headers(header...).
Rows(rows...)

return t.String(), nil
}