Commit 697efd1b authored by xilabao's avatar xilabao

De-duplication in printer

parent 35159f9c
......@@ -300,7 +300,7 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona
}
}
name := formatResourceName(options.Kind, metadata.GetName(), options.WithKind)
name := FormatResourceName(options.Kind, metadata.GetName(), options.WithKind)
if _, err := fmt.Fprintf(w, "%s\t%s", name, kind); err != nil {
return err
......@@ -319,10 +319,10 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona
}
}
}
if _, err := fmt.Fprint(w, appendLabels(metadata.GetLabels(), options.ColumnLabels)); err != nil {
if _, err := fmt.Fprint(w, AppendLabels(metadata.GetLabels(), options.ColumnLabels)); err != nil {
return err
}
if _, err := fmt.Fprint(w, appendAllLabels(options.ShowLabels, metadata.GetLabels())); err != nil {
if _, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, metadata.GetLabels())); err != nil {
return err
}
......@@ -349,10 +349,9 @@ func formatShowLabelsHeader(showLabels bool, t reflect.Type) []string {
return nil
}
// formatResourceName receives a resource kind, name, and boolean specifying
// FormatResourceName receives a resource kind, name, and boolean specifying
// whether or not to update the current name to "kind/name"
// TODO: dedup this with printers/internalversions
func formatResourceName(kind, name string, withKind bool) string {
func FormatResourceName(kind, name string, withKind bool) string {
if !withKind || kind == "" {
return name
}
......@@ -360,8 +359,7 @@ func formatResourceName(kind, name string, withKind bool) string {
return kind + "/" + name
}
// TODO: dedup this with printers/internalversions
func appendLabels(itemLabels map[string]string, columnLabels []string) string {
func AppendLabels(itemLabels map[string]string, columnLabels []string) string {
var buffer bytes.Buffer
for _, cl := range columnLabels {
......@@ -378,8 +376,7 @@ func appendLabels(itemLabels map[string]string, columnLabels []string) string {
// Append all labels to a single column. We need this even when show-labels flag* is
// false, since this adds newline delimiter to the end of each row.
// TODO: dedup this with printers/internalversions
func appendAllLabels(showLabels bool, itemLabels map[string]string) string {
func AppendAllLabels(showLabels bool, itemLabels map[string]string) string {
var buffer bytes.Buffer
if showLabels {
......
......@@ -236,7 +236,7 @@ func TestFormatResourceName(t *testing.T) {
{"kind", "name", "kind/name"},
}
for _, tt := range tests {
if got := formatResourceName(tt.kind, tt.name, true); got != tt.want {
if got := printers.FormatResourceName(tt.kind, tt.name, true); got != tt.want {
t.Errorf("formatResourceName(%q, %q) = %q, want %q", tt.kind, tt.name, got, tt.want)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment