From a3b67e460790793e3223f3e3fcdab9d2f11238e3 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Tue, 30 Jan 2018 10:54:13 +0000 Subject: [PATCH] add available connectors to help dialog --- connector/main.go | 22 ++++++++++++++-------- main.go | 5 ++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/connector/main.go b/connector/main.go index c19c1de..9162d77 100644 --- a/connector/main.go +++ b/connector/main.go @@ -2,6 +2,7 @@ package connector import ( "fmt" + "sort" "github.com/bcicen/ctop/container" "github.com/bcicen/ctop/logging" @@ -12,15 +13,20 @@ var ( enabled = make(map[string]func() Connector) ) -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) +// return names for all enabled connectors on the current platform +func Enabled() (a []string) { + for k, _ := range enabled { + a = append(a, k) } - return enabled[s](), nil + sort.Strings(a) + return a +} + +func ByName(s string) (Connector, error) { + if cfn, ok := enabled[s]; ok { + return cfn(), nil + } + return nil, fmt.Errorf("invalid connector type \"%s\"", s) } type Connector interface { diff --git a/main.go b/main.go index 2301482..c43f11b 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "runtime" + "strings" "github.com/bcicen/ctop/config" "github.com/bcicen/ctop/connector" @@ -138,7 +139,7 @@ func panicExit() { } } -var helpMsg = `ctop - container metric viewer +var helpMsg = `ctop - interactive container viewer usage: ctop [options] @@ -148,4 +149,6 @@ options: func printHelp() { fmt.Println(helpMsg) flag.PrintDefaults() + fmt.Printf("\navailable connectors: ") + fmt.Println(strings.Join(connector.Enabled(), ", ")) }