-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6edd9c3
commit 8b2cad0
Showing
1,618 changed files
with
225 additions
and
668,971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package client | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"sort" | ||
"text/tabwriter" | ||
) | ||
|
||
const ( | ||
tabwriterMinWidth = 8 | ||
tabwriterWidth = 8 | ||
tabwriterPadding = 1 | ||
tabwriterPadChar = '\t' | ||
) | ||
|
||
func sortPodResources(res []*PodResource) { | ||
sort.Slice(res, func(i, j int) bool { | ||
if res[i].Namespace != res[j].Namespace { | ||
return res[i].Namespace < res[j].Namespace | ||
} | ||
return res[i].Name < res[j].Name | ||
}) | ||
} | ||
|
||
func Write(response map[string]*PodResource) error { | ||
resources := make([]*PodResource, 0, len(response)) | ||
for _, res := range response { | ||
resources = append(resources, res) | ||
} | ||
sortPodResources(resources) | ||
|
||
w := getNewTabWriter(os.Stdout) | ||
if _, err := w.Write([]byte("NAME\tNAMESPACE\tNODE\n")); err != nil { | ||
return err | ||
} | ||
for _, pod := range resources { | ||
if _, err := w.Write([]byte(pod.Name + "\t" + pod.Namespace + "\t" + pod.Node + "\n")); err != nil { | ||
return err | ||
} | ||
} | ||
return w.Flush() | ||
} | ||
|
||
// GetNewTabWriter returns a tabwriter that translates tabbed columns in input into properly aligned text. | ||
func getNewTabWriter(output io.Writer) *tabwriter.Writer { | ||
return tabwriter.NewWriter(output, tabwriterMinWidth, tabwriterWidth, tabwriterPadding, tabwriterPadChar, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.