diff --git a/cmd/conduit/internal/print_utils.go b/cmd/conduit/internal/print_utils.go index b910275c0..be8214c58 100644 --- a/cmd/conduit/internal/print_utils.go +++ b/cmd/conduit/internal/print_utils.go @@ -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" + } +} diff --git a/cmd/conduit/internal/print_utils_test.go b/cmd/conduit/internal/print_utils_test.go index d8bc7192c..f8cc1081b 100644 --- a/cmd/conduit/internal/print_utils_test.go +++ b/cmd/conduit/internal/print_utils_test.go @@ -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) + }) + } +} diff --git a/cmd/conduit/root/processors/describe.go b/cmd/conduit/root/processors/describe.go index 2e4e2189f..ca82ba19e 100644 --- a/cmd/conduit/root/processors/describe.go +++ b/cmd/conduit/root/processors/describe.go @@ -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) diff --git a/cmd/conduit/root/processors/list.go b/cmd/conduit/root/processors/list.go index b43f2f673..294f7206b 100644 --- a/cmd/conduit/root/processors/list.go +++ b/cmd/conduit/root/processors/list.go @@ -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)}, }