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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/container"
|
"github.com/bcicen/ctop/container"
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
@ -12,15 +13,20 @@ var (
|
|||||||
enabled = make(map[string]func() Connector)
|
enabled = make(map[string]func() Connector)
|
||||||
)
|
)
|
||||||
|
|
||||||
func ByName(s string) (Connector, error) {
|
// return names for all enabled connectors on the current platform
|
||||||
if _, ok := enabled[s]; !ok {
|
func Enabled() (a []string) {
|
||||||
msg := fmt.Sprintf("invalid connector type \"%s\"\nconnector must be one of:", s)
|
for k, _ := range enabled {
|
||||||
for k, _ := range enabled {
|
a = append(a, k)
|
||||||
msg += fmt.Sprintf("\n %s", k)
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf(msg)
|
|
||||||
}
|
}
|
||||||
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 {
|
type Connector interface {
|
||||||
|
5
main.go
5
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/config"
|
"github.com/bcicen/ctop/config"
|
||||||
"github.com/bcicen/ctop/connector"
|
"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]
|
usage: ctop [options]
|
||||||
|
|
||||||
@ -148,4 +149,6 @@ options:
|
|||||||
func printHelp() {
|
func printHelp() {
|
||||||
fmt.Println(helpMsg)
|
fmt.Println(helpMsg)
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
fmt.Printf("\navailable connectors: ")
|
||||||
|
fmt.Println(strings.Join(connector.Enabled(), ", "))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user