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

refactor: update type on processors ls #2097

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions cmd/conduit/internal/print_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,17 @@ func ConnectorTypeToString(connectorType apiv1.Connector_Type) string {
return "unknown"
}
}

// ProcessorParentToString returns a human-readable string from a processor parent type
func ProcessorParentToString(processorParentType apiv1.Processor_Parent_Type) string {
switch processorParentType {
case apiv1.Processor_Parent_TYPE_CONNECTOR:
return "connector"
case apiv1.Processor_Parent_TYPE_PIPELINE:
return "pipeline"
case apiv1.Processor_Parent_TYPE_UNSPECIFIED:
return "unspecified"
default:
return "unknown"
}
}
31 changes: 31 additions & 0 deletions cmd/conduit/internal/print_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,34 @@ func TestConnectorTypeToString(t *testing.T) {
})
}
}

func TestProcessorParentTypeToString(t *testing.T) {
is := is.New(t)

tests := []struct {
name string
processorParentType apiv1.Processor_Parent_Type
want string
}{
{
name: "Connector",
processorParentType: apiv1.Processor_Parent_TYPE_CONNECTOR,
want: "connector",
},
{
name: "Pipeline",
processorParentType: apiv1.Processor_Parent_TYPE_PIPELINE,
want: "pipeline",
},
{
name: "Unspecified",
processorParentType: apiv1.Processor_Parent_TYPE_UNSPECIFIED,
want: "unspecified",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
is.Equal(ProcessorParentToString(tt.processorParentType), tt.want)
})
}
}
12 changes: 1 addition & 11 deletions cmd/conduit/root/processors/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ func displayProcessor(p *apiv1.Processor) {
fmt.Printf("ID: %s\n", p.Id)
fmt.Printf("Plugin: %s\n", p.Plugin)

processorType := "Processor "
switch p.Parent.Type.String() {
case "TYPE_PIPELINE":
processorType += "for Pipeline"
case "TYPE_CONNECTOR":
processorType += "for Connector"
default:
processorType += "associated to"
}

fmt.Printf("%s: %s\n", processorType, p.Parent.Id)
fmt.Printf("Parent: %s (%s)\n", internal.ProcessorParentToString(p.Parent.Type), p.Parent.Id)

if !internal.IsEmpty(p.Condition) {
fmt.Printf("Condition: %s\n", p.Condition)
Expand Down
18 changes: 3 additions & 15 deletions cmd/conduit/root/processors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,20 @@ func displayProcessors(processors []*apiv1.Processor) {
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "PLUGIN"},
{Align: simpletable.AlignCenter, Text: "PARENT"},
{Align: simpletable.AlignCenter, Text: "CONDITION"},
{Align: simpletable.AlignCenter, Text: "TYPE"},
{Align: simpletable.AlignCenter, Text: "CREATED"},
{Align: simpletable.AlignCenter, Text: "LAST_UPDATED"},
},
}

for _, p := range processors {
var processorType string

switch p.Parent.Type.String() {
case "TYPE_PIPELINE":
processorType = "Pipeline"
case "TYPE_CONNECTOR":
processorType = "Connector"
default:
processorType = "Unknown"
}

processorType = fmt.Sprintf("%s (%s)", processorType, p.Parent.Id)

processorParent := fmt.Sprintf("%s (%s)", internal.ProcessorParentToString(p.Parent.Type), p.Parent.Id)
r := []*simpletable.Cell{
{Align: simpletable.AlignLeft, Text: p.Id},
{Align: simpletable.AlignLeft, Text: p.Plugin},
{Align: simpletable.AlignLeft, Text: processorParent},
{Align: simpletable.AlignLeft, Text: p.Condition},
{Align: simpletable.AlignLeft, Text: processorType},
{Align: simpletable.AlignLeft, Text: internal.PrintTime(p.CreatedAt)},
{Align: simpletable.AlignLeft, Text: internal.PrintTime(p.UpdatedAt)},
}
Expand Down
Loading