Skip to content

Commit

Permalink
omit runc connector from darwin build
Browse files Browse the repository at this point in the history
  • Loading branch information
bcicen committed Jun 14, 2017
1 parent e59a360 commit 617b1b2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 29 deletions.
2 changes: 2 additions & 0 deletions connector/collector/proc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !darwin

package collector

import (
Expand Down
2 changes: 2 additions & 0 deletions connector/collector/runc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !darwin

package collector

import (
Expand Down
1 change: 0 additions & 1 deletion connector/docker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// +build ignore
package connector

import (
Expand Down
7 changes: 7 additions & 0 deletions connector/enabled_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !linux

package connector

var enabled = map[string]func() Connector{
"docker": NewDocker,
}
8 changes: 8 additions & 0 deletions connector/enabled_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build !darwin

package connector

var enabled = map[string]func() Connector{
"docker": NewDocker,
"runc": NewRunc,
}
13 changes: 13 additions & 0 deletions connector/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package connector

import (
"fmt"

"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/logging"
)

var log = logging.Init()

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 enabled[s](), nil
}

type Connector interface {
All() container.Containers
Get(string) (*container.Container, bool)
Expand Down
2 changes: 2 additions & 0 deletions connector/runc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !darwin

package connector

import (
Expand Down
11 changes: 0 additions & 11 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@ import (
ui "github.com/gizak/termui"
)

var enabledConnectors = map[string]func() connector.Connector{
"docker": connector.NewDocker,
"runc": connector.NewRunc,
}

type GridCursor struct {
selectedID string // id of currently selected container
filtered container.Containers
cSource connector.Connector
isScrolling bool // toggled when actively scrolling
}

func NewGridCursor(connectorName string) *GridCursor {
return &GridCursor{
cSource: enabledConnectors[connectorName](),
}
}

func (gc *GridCursor) Len() int { return len(gc.filtered) }

func (gc *GridCursor) Selected() *container.Container {
Expand Down
24 changes: 7 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"flag"
"fmt"
"os"
"strings"

"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/connector"
"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/cwidgets/compact"
"github.com/bcicen/ctop/logging"
Expand Down Expand Up @@ -41,8 +41,6 @@ func main() {
var connectorFlag = flag.String("connector", "docker", "container connector to use")
flag.Parse()

validConnector(*connectorFlag)

if *versionFlag {
fmt.Println(versionStr)
os.Exit(0)
Expand Down Expand Up @@ -88,7 +86,11 @@ func main() {

defer Shutdown()
// init grid, cursor, header
cursor = NewGridCursor(*connectorFlag)
conn, err := connector.ByName(*connectorFlag)
if err != nil {
panic(err)
}
cursor = &GridCursor{cSource: conn}
cGrid = compact.NewCompactGrid()
header = widgets.NewCTopHeader()

Expand All @@ -108,18 +110,6 @@ func Shutdown() {
}
}

func validConnector(s string) {
if _, ok := enabledConnectors[s]; !ok {
fmt.Printf("invalid connector type: %s\n", s)
var connectors []string
for k, _ := range enabledConnectors {
connectors = append(connectors, k)
}
fmt.Printf("connector must be one of: %s\n", strings.Join(connectors, ","))
os.Exit(1)
}
}

// ensure a given sort field is valid
func validSort(s string) {
if _, ok := container.Sorters[s]; !ok {
Expand All @@ -131,7 +121,7 @@ func validSort(s string) {
func panicExit() {
if r := recover(); r != nil {
Shutdown()
fmt.Printf("panic: %s\n", r)
fmt.Printf("error: %s\n", r)
os.Exit(1)
}
}
Expand Down

0 comments on commit 617b1b2

Please sign in to comment.