コード例 #1
0
//XXX test with multiple containers of same definition!
func AssembleTable(typ string) ([]Parts, error) {

	typ = strings.TrimSuffix(typ, "s") // :(
	// []*ContainerName
	contsR := util.ErisContainersByType(typ, false) //running
	contsE := util.ErisContainersByType(typ, true)  //existing

	if len(contsE) == 0 && len(contsR) == 0 {
		return []Parts{}, nil
	}

	var myTable []Parts
	addedAlready := make(map[string]bool)

	for _, name := range contsR {
		part, _ := makePartFromContainer(name.FullName)
		addedAlready[part.ShortName] = true //has to come after because short name needed
		part.Running = true
		myTable = append(myTable, part)
	}

	for _, name := range contsE {
		part, _ := makePartFromContainer(name.FullName)
		if addedAlready[part.ShortName] == true {
			continue
		} else {
			part.Running = false
			myTable = append(myTable, part)
		}
	}
	return myTable, nil
}
コード例 #2
0
ファイル: docker_stats.go プロジェクト: kustomzone/eris-cli
func PrintTableReport(typ string, running bool) error {
	logger.Debugf("PrintTableReport Initialized =>\t%s:%v\n", typ, running)
	conts := util.ErisContainersByType(typ, running)
	if len(conts) == 0 {
		return nil
	}

	var head string
	if typ == "chain" {
		head, _ = util.GetHead()
	}

	table := tablewriter.NewWriter(config.GlobalConfig.Writer)
	table.SetHeader([]string{"SERVICE NAME", "CONTAINER NAME", "TYPE", "CONTAINER #", "PORTS"})
	for _, c := range conts {
		n, _ := PrintLineByContainerName(c.FullName)
		if typ == "chain" {
			if n[0] == head {
				n[0] = fmt.Sprintf("**  %s", n[0]) // TODO: colorize this when we settle on a lib
			}
		}
		table.Append(n)
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()
	return nil
}
コード例 #3
0
ファイル: testing_utils.go プロジェクト: antonylewis/eris-cli
// FindContainer returns true if the container with a given
// short name, type, number, and status exists.
func FindContainer(name, t string, n int, running bool) bool {
	containers := util.ErisContainersByType(t, !running)

	for _, c := range containers {
		if c.ShortName == name && c.Number == n {
			return true
		}
	}
	return false
}
コード例 #4
0
func PrintTableReport(typ string, existing, all bool) (string, error) {
	log.WithField("type", typ).Debug("Table report initialized")

	var conts []*util.ContainerName
	if !all {
		conts = util.ErisContainersByType(typ, existing)
	}
	// "MACHINE" is placeholder
	header := []string{"NAME", "MACHINE", "RUNNING", "CONTAINER NAME", "PORTS"}
	if err := util.CheckParts(header); err != nil {
		log.Error(err) // err is silenced by some funcs
		return "", err
	}

	buf := new(bytes.Buffer)
	table := tablewriter.NewWriter(buf)
	//name set by logger instead
	table.SetHeader(header)

	if all { //get all the things
		parts, _ := AssembleTable(typ)
		for _, p := range parts {
			table.Append(formatLine(p))
		}
	} else {
		for _, c := range conts {
			n, _ := PrintLineByContainerName(c.FullName, existing)
			if typ == "chain" {
				head, _ := util.GetHead()
				if n[0] == head {
					n[0] = fmt.Sprintf("**  %s", n[0])
				}
			}
			table.Append(n)
		}
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()

	return buf.String(), nil
}
コード例 #5
0
ファイル: docker_stats.go プロジェクト: slowtokyo/eris-cli
func PrintTableReport(typ string, running bool) error {
	logger.Debugf("PrintTableReport Initialized =>\t%s:%v\n", typ, running)
	conts := util.ErisContainersByType(typ, running)
	if len(conts) == 0 {
		return nil
	}

	table := tablewriter.NewWriter(util.GlobalConfig.Writer)
	table.SetHeader([]string{"SERVICE NAME", "CONTAINER NAME", "TYPE", "CONTAINER #", "PORTS"})
	for _, c := range conts {
		n, _ := PrintLineByContainerName(c.FullName)
		table.Append(n)
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()
	return nil
}