Esempio n. 1
0
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
}
Esempio n. 2
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
}
Esempio n. 3
0
func PrintTableReport(typ string, existing, all bool) (string, error) {
	logger.Debugf("PrintTableReport Initialized =>\t%s", typ)

	var conts []*ContainerName
	if !all {
		conts = ErisContainersByType(typ, existing)
	}

	buf := new(bytes.Buffer)
	table := tablewriter.NewWriter(buf)
	table.SetHeader([]string{fmt.Sprintf("%s NAME", strings.ToUpper(typ)), "TYPE", "RUNNING", "CONTAINER NAME", "CONTAINER #", "PORTS"})

	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, _ := GetHead()
				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 buf.String(), nil
}
Esempio n. 4
0
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
}