Skip to content

Commit

Permalink
refactor: update type on processors ls (#2097)
Browse files Browse the repository at this point in the history
* feat: show type on processors ls

* use parent instead

* fix
  • Loading branch information
raulb authored Jan 23, 2025
1 parent 99517c7 commit 170fa09
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
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

0 comments on commit 170fa09

Please sign in to comment.