Skip to content

Commit

Permalink
add available connectors to help dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bcicen committed Jan 30, 2018
1 parent ac1ce18 commit a3b67e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 13 additions & 7 deletions connector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connector

import (
"fmt"
"sort"

"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/logging"
Expand All @@ -12,15 +13,20 @@ var (
enabled = make(map[string]func() Connector)
)

// return names for all enabled connectors on the current platform
func Enabled() (a []string) {
for k, _ := range enabled {
a = append(a, k)
}
sort.Strings(a)
return a
}

func ByName(s string) (Connector, error) {
if _, ok := enabled[s]; !ok {
msg := fmt.Sprintf("invalid connector type \"%s\"\nconnector must be one of:", s)
for k, _ := range enabled {
msg += fmt.Sprintf("\n %s", k)
}
return nil, fmt.Errorf(msg)
if cfn, ok := enabled[s]; ok {
return cfn(), nil
}
return enabled[s](), nil
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
}

type Connector interface {
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"strings"

"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/connector"
Expand Down Expand Up @@ -138,7 +139,7 @@ func panicExit() {
}
}

var helpMsg = `ctop - container metric viewer
var helpMsg = `ctop - interactive container viewer
usage: ctop [options]
Expand All @@ -148,4 +149,6 @@ options:
func printHelp() {
fmt.Println(helpMsg)
flag.PrintDefaults()
fmt.Printf("\navailable connectors: ")
fmt.Println(strings.Join(connector.Enabled(), ", "))
}

0 comments on commit a3b67e4

Please sign in to comment.