Exemple #1
0
Fichier : list.go Projet : bac/juju
// formatCloudsTabular writes a tabular summary of cloud information.
func formatCloudsTabular(writer io.Writer, value interface{}) error {
	clouds, ok := value.(*cloudList)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", clouds, value)
	}

	tw := output.TabWriter(writer)
	w := output.Wrapper{tw}
	w.Println("Cloud", "Regions", "Default", "Type", "Description")
	w.SetColumnAlignRight(1)

	cloudNamesSorted := func(someClouds map[string]*cloudDetails) []string {
		// For tabular we'll sort alphabetically, user clouds last.
		var names []string
		for name, _ := range someClouds {
			names = append(names, name)
		}
		sort.Strings(names)
		return names
	}

	printClouds := func(someClouds map[string]*cloudDetails, color *ansiterm.Context) {
		cloudNames := cloudNamesSorted(someClouds)

		for _, name := range cloudNames {
			info := someClouds[name]
			defaultRegion := ""
			if len(info.Regions) > 0 {
				defaultRegion = info.RegionsMap[info.Regions[0].Key.(string)].Name
			}
			description := info.CloudDescription
			if len(description) > 40 {
				description = description[:39]
			}
			w.PrintColor(color, name)
			w.Println(len(info.Regions), defaultRegion, info.CloudType, description)
		}
	}
	printClouds(clouds.public, nil)
	printClouds(clouds.builtin, nil)
	printClouds(clouds.personal, ansiterm.Foreground(ansiterm.BrightBlue))

	w.Println("\nTry 'list-regions <cloud>' to see available regions.")
	w.Println("'show-cloud <cloud>' or 'regions --format yaml <cloud>' can be used to see region endpoints.")
	w.Println("'add-cloud' can add private clouds or private infrastructure.")
	w.Println("Update the known public clouds with 'update-clouds'.")
	tw.Flush()
	return nil
}
Exemple #2
0
func (w *Wrapper) PrintColor(ctx *ansiterm.Context, value interface{}) {
	if ctx != nil {
		ctx.Fprintf(w.TabWriter, "%v\t", value)
	} else {
		fmt.Fprintf(w, "%v\t", value)
	}
}

// PrintStatus writes out the status value in the standard color.
func (w *Wrapper) PrintStatus(status status.Status) {
	w.PrintColor(statusColors[status], status)
}

// CurrentHighlight is the color used to show the current
// controller, user or model in tabular
var CurrentHighlight = ansiterm.Foreground(ansiterm.Green)

// ErrorHighlight is the color used to show error conditions.
var ErrorHighlight = ansiterm.Foreground(ansiterm.Red)

// WarningHighlight is the color used to show warning conditions.
// Generally things that the user should be aware of, but not necessarily
// requiring any user action.
var WarningHighlight = ansiterm.Foreground(ansiterm.Yellow)

// GoodHighlight is used to indicate good or success conditions.
var GoodHighlight = ansiterm.Foreground(ansiterm.Green)

var statusColors = map[status.Status]*ansiterm.Context{
	// good
	status.Active:  GoodHighlight,
Exemple #3
0
	logLine := simple.formatter(entry)
	fmt.Fprintln(simple.writer, logLine)
}

func defaultWriter() Writer {
	return NewColorWriter(os.Stderr)
}

type colorWriter struct {
	writer *ansiterm.Writer
}

var (
	// SeverityColor defines the colors for the levels output by the ColorWriter.
	SeverityColor = map[Level]*ansiterm.Context{
		TRACE:   ansiterm.Foreground(ansiterm.Default),
		DEBUG:   ansiterm.Foreground(ansiterm.Green),
		INFO:    ansiterm.Foreground(ansiterm.BrightBlue),
		WARNING: ansiterm.Foreground(ansiterm.Yellow),
		ERROR:   ansiterm.Foreground(ansiterm.BrightRed),
		CRITICAL: &ansiterm.Context{
			Foreground: ansiterm.White,
			Background: ansiterm.Red,
		},
	}
	// LocationColor defines the colors for the location output by the ColorWriter.
	LocationColor = ansiterm.Foreground(ansiterm.BrightBlue)
)

// NewColorWriter will write out colored severity levels if the writer is
// outputting to a terminal.
Exemple #4
0
	if c.color {
		writer.SetColorCapable(true)
	}
	for {
		msg, ok := <-messages
		if !ok {
			break
		}
		c.writeLogRecord(writer, msg)
	}

	return nil
}

var SeverityColor = map[string]*ansiterm.Context{
	"TRACE":   ansiterm.Foreground(ansiterm.Default),
	"DEBUG":   ansiterm.Foreground(ansiterm.Green),
	"INFO":    ansiterm.Foreground(ansiterm.BrightBlue),
	"WARNING": ansiterm.Foreground(ansiterm.Yellow),
	"ERROR":   ansiterm.Foreground(ansiterm.BrightRed),
	"CRITICAL": &ansiterm.Context{
		Foreground: ansiterm.White,
		Background: ansiterm.Red,
	},
}

func (c *debugLogCommand) writeLogRecord(w *ansiterm.Writer, r api.LogMessage) {
	ts := r.Timestamp.In(c.tz).Format(c.format)
	fmt.Fprintf(w, "%s: %s ", r.Entity, ts)
	SeverityColor[r.Severity].Fprintf(w, r.Severity)
	fmt.Fprintf(w, " %s ", r.Module)