mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add available connectors to help dialog
This commit is contained in:
parent
ac1ce18143
commit
a3b67e4607
@ -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 {
|
||||
|
5
main.go
5
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(), ", "))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user