Skip to content

Commit

Permalink
Add support for -v flag
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn committed Jun 28, 2019
1 parent b28dc58 commit af754d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Args struct {
KubeConfig string
NamespaceBlacklist []string
Aggregation Aggregation
Verbose bool
}

func Run(args *Args) error {
Expand Down
10 changes: 9 additions & 1 deletion client/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func Write(response map[string]*PodResource, args *Args) error {
resources = append(resources, res)
}
sortPodResources(resources)
simplifyNames(resources)
if !args.Verbose {
simplifyNames(resources)
}

w := getNewTabWriter(os.Stdout)
if _, err := w.Write([]byte(formatHeader(args))); err != nil {
Expand Down Expand Up @@ -112,10 +114,16 @@ func formatRow(pod *PodResource, args *Args) []string {
}

func formatCpu(i int64) string {
if i == 0 {
return "-"
}
return strconv.FormatInt(i, 10) + "m"
}

func formatMemory(i int64) string {
if i == 0 {
return "-"
}
mb := int64(float64(i) / (1024 * 1024 * 1024))
return strconv.FormatInt(mb, 10) + "Mi"
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
kubeConfig = path.Join(os.Getenv("HOME"), ".kube", "config")
namespaceBlacklist = []string{"kube-system"}
showContainers = false
verbose = false
)

func init() {
Expand All @@ -32,6 +33,13 @@ func init() {
showContainers,
"Include container level details",
)
rootCmd.PersistentFlags().BoolVarP(
&verbose,
"verbose",
"v",
verbose,
"Show full resource names",
)
}

var rootCmd = &cobra.Command{
Expand All @@ -47,6 +55,7 @@ var rootCmd = &cobra.Command{
KubeConfig: kubeConfig,
NamespaceBlacklist: namespaceBlacklist,
Aggregation: aggregation,
Verbose: verbose,
}
return client.Run(args)
},
Expand Down

0 comments on commit af754d3

Please sign in to comment.