本文整理汇总了Golang中github.com/juju/juju/cmd/output.TabWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang TabWriter函数的具体用法?Golang TabWriter怎么用?Golang TabWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TabWriter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: formatConfigTabular
// formatConfigTabular writes a tabular summary of config information.
func formatConfigTabular(writer io.Writer, value interface{}) error {
configValues, ok := value.(config.ConfigValues)
if !ok {
return errors.Errorf("expected value of type %T, got %T", configValues, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
var valueNames []string
for name := range configValues {
valueNames = append(valueNames, name)
}
sort.Strings(valueNames)
w.Println("Attribute", "From", "Value")
for _, name := range valueNames {
info := configValues[name]
out := &bytes.Buffer{}
err := cmd.FormatYaml(out, info.Value)
if err != nil {
return errors.Annotatef(err, "formatting value for %q", name)
}
// Some attribute values have a newline appended
// which makes the output messy.
valString := strings.TrimSuffix(out.String(), "\n")
w.Println(name, info.Source, valString)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:33,代码来源:configcommand.go
示例2: formatServiceDetailTabular
func formatServiceDetailTabular(writer io.Writer, resources FormattedServiceDetails) {
// note that the unit resource can be a zero value here, to indicate that
// the unit has not downloaded that resource yet.
fmt.Fprintln(writer, "[Units]")
sort.Sort(byUnitID(resources.Resources))
// To format things into columns.
tw := output.TabWriter(writer)
// Write the header.
fmt.Fprintln(tw, "Unit\tResource\tRevision\tExpected")
for _, r := range resources.Resources {
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n",
r.unitNumber,
r.Expected.Name,
r.Unit.combinedRevision,
r.revProgress,
)
}
tw.Flush()
writeUpdates(resources.Updates, writer, tw)
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:output_tabular.go
示例3: FormatTabular
// FormatTabular writes a tabular summary of payloads.
func FormatTabular(writer io.Writer, value interface{}) error {
payloads, valueConverted := value.([]FormattedPayload)
if !valueConverted {
return errors.Errorf("expected value of type %T, got %T", payloads, value)
}
// TODO(ericsnow) sort the rows first?
tw := output.TabWriter(writer)
// Write the header.
fmt.Fprintln(tw, tabularSection)
fmt.Fprintln(tw, tabularHeader)
// Print each payload to its own row.
for _, payload := range payloads {
// tabularColumns must be kept in sync with these.
fmt.Fprintf(tw, tabularRow+"\n",
payload.Unit,
payload.Machine,
payload.Class,
payload.Status,
payload.Type,
payload.ID,
strings.Join(payload.Labels, " "),
)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:output_tabular.go
示例4: formatModelUsers
func (c *listCommand) formatModelUsers(writer io.Writer, value interface{}) error {
users, ok := value.(map[string]common.ModelUserInfo)
if !ok {
return errors.Errorf("expected value of type %T, got %T", users, value)
}
modelUsers := set.NewStrings()
for name := range users {
modelUsers.Add(name)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
w.Println("Name", "Display name", "Access", "Last connection")
for _, name := range modelUsers.SortedValues() {
user := users[name]
var highlight *ansiterm.Context
userName := name
if c.isLoggedInUser(name) {
userName += "*"
highlight = output.CurrentHighlight
}
w.PrintColor(highlight, userName)
w.Println(user.DisplayName, user.Access, user.LastConnection)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:list.go
示例5: formatControllerUsers
func (c *listCommand) formatControllerUsers(writer io.Writer, value interface{}) error {
users, valueConverted := value.([]UserInfo)
if !valueConverted {
return errors.Errorf("expected value of type %T, got %T", users, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
w.Println("Controller: " + c.ControllerName())
w.Println()
w.Println("Name", "Display name", "Access", "Date created", "Last connection")
for _, user := range users {
conn := user.LastConnection
if user.Disabled {
conn += " (disabled)"
}
var highlight *ansiterm.Context
userName := user.Username
if c.isLoggedInUser(user.Username) {
userName += "*"
highlight = output.CurrentHighlight
}
w.PrintColor(highlight, userName)
w.Println(user.DisplayName, user.Access, user.DateCreated, conn)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:list.go
示例6: FormatCharmTabular
// FormatCharmTabular returns a tabular summary of charm resources.
func FormatCharmTabular(writer io.Writer, value interface{}) error {
resources, valueConverted := value.([]FormattedCharmResource)
if !valueConverted {
return errors.Errorf("expected value of type %T, got %T", resources, value)
}
// TODO(ericsnow) sort the rows first?
// To format things into columns.
tw := output.TabWriter(writer)
// Write the header.
// We do not print a section label.
fmt.Fprintln(tw, "Resource\tRevision")
// Print each info to its own row.
for _, res := range resources {
// the column headers must be kept in sync with these.
fmt.Fprintf(tw, "%s\t%d\n",
res.Name,
res.Revision,
)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:output_tabular.go
示例7: formatPoolsTabular
// formatPoolsTabular returns a tabular summary of pool instances.
func formatPoolsTabular(writer io.Writer, pools map[string]PoolInfo) {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
print("Name", "Provider", "Attrs")
poolNames := make([]string, 0, len(pools))
for name := range pools {
poolNames = append(poolNames, name)
}
sort.Strings(poolNames)
for _, name := range poolNames {
pool := pools[name]
// order by key for deterministic return
keys := make([]string, 0, len(pool.Attrs))
for key := range pool.Attrs {
keys = append(keys, key)
}
sort.Strings(keys)
attrs := make([]string, len(pool.Attrs))
for i, key := range keys {
attrs[i] = fmt.Sprintf("%v=%v", key, pool.Attrs[key])
}
print(name, pool.Provider, strings.Join(attrs, " "))
}
tw.Flush()
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:poollistformatters.go
示例8: formatRegionsTabular
func formatRegionsTabular(writer io.Writer, regions yaml.MapSlice) error {
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
for _, r := range regions {
w.Println(r.Key)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:regions.go
示例9: newSummaryFormatter
func newSummaryFormatter(writer io.Writer) *summaryFormatter {
f := &summaryFormatter{
ipAddrs: make([]net.IPNet, 0),
netStrings: make([]string, 0),
openPorts: set.NewStrings(),
stateToUnit: make(map[status.Status]int),
}
f.tw = output.TabWriter(writer)
return f
}
开发者ID:bac,项目名称:juju,代码行数:10,代码来源:output_summary.go
示例10: formatCloudsTabular
// 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)
p := func(values ...string) {
text := strings.Join(values, "\t")
fmt.Fprintln(tw, text)
}
p("CLOUD\tTYPE\tREGIONS")
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) {
cloudNames := cloudNamesSorted(someClouds)
for _, name := range cloudNames {
info := someClouds[name]
var regions []string
for _, region := range info.Regions {
regions = append(regions, fmt.Sprint(region.Key))
}
// TODO(wallyworld) - we should be smarter about handling
// long region text, for now we'll display the first 7 as
// that covers all clouds except AWS and Azure and will
// prevent wrapping on a reasonable terminal width.
regionCount := len(regions)
if regionCount > 7 {
regionCount = 7
}
regionText := strings.Join(regions[:regionCount], ", ")
if len(regions) > 7 {
regionText = regionText + " ..."
}
p(name, info.CloudType, regionText)
}
}
printClouds(clouds.public)
printClouds(clouds.builtin)
printClouds(clouds.personal)
tw.Flush()
return nil
}
开发者ID:kat-co,项目名称:juju,代码行数:55,代码来源:list.go
示例11: formatVolumeListTabular
// formatVolumeListTabular returns a tabular summary of volume instances.
func formatVolumeListTabular(writer io.Writer, infos map[string]VolumeInfo) error {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
print("Machine", "Unit", "Storage", "Id", "Provider Id", "Device", "Size", "State", "Message")
volumeAttachmentInfos := make(volumeAttachmentInfos, 0, len(infos))
for volumeId, info := range infos {
volumeAttachmentInfo := volumeAttachmentInfo{
VolumeId: volumeId,
VolumeInfo: info,
}
if info.Attachments == nil {
volumeAttachmentInfos = append(volumeAttachmentInfos, volumeAttachmentInfo)
continue
}
// Each unit attachment must have a corresponding volume
// attachment. Enumerate each of the volume attachments,
// and locate the corresponding unit attachment if any.
// Each volume attachment has at most one corresponding
// unit attachment.
for machineId, machineInfo := range info.Attachments.Machines {
volumeAttachmentInfo := volumeAttachmentInfo
volumeAttachmentInfo.MachineId = machineId
volumeAttachmentInfo.MachineVolumeAttachment = machineInfo
for unitId, unitInfo := range info.Attachments.Units {
if unitInfo.MachineId == machineId {
volumeAttachmentInfo.UnitId = unitId
volumeAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
volumeAttachmentInfos = append(volumeAttachmentInfos, volumeAttachmentInfo)
}
}
sort.Sort(volumeAttachmentInfos)
for _, info := range volumeAttachmentInfos {
var size string
if info.Size > 0 {
size = humanize.IBytes(info.Size * humanize.MiByte)
}
print(
info.MachineId, info.UnitId, info.Storage,
info.VolumeId, info.ProviderVolumeId,
info.DeviceName, size,
string(info.Status.Current), info.Status.Message,
)
}
return tw.Flush()
}
开发者ID:bac,项目名称:juju,代码行数:55,代码来源:volumelistformatters.go
示例12: formatFilesystemListTabular
// formatFilesystemListTabular writes a tabular summary of filesystem instances.
func formatFilesystemListTabular(writer io.Writer, infos map[string]FilesystemInfo) error {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
print("MACHINE", "UNIT", "STORAGE", "ID", "VOLUME", "PROVIDER-ID", "MOUNTPOINT", "SIZE", "STATE", "MESSAGE")
filesystemAttachmentInfos := make(filesystemAttachmentInfos, 0, len(infos))
for filesystemId, info := range infos {
filesystemAttachmentInfo := filesystemAttachmentInfo{
FilesystemId: filesystemId,
FilesystemInfo: info,
}
if info.Attachments == nil {
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
continue
}
// Each unit attachment must have a corresponding filesystem
// attachment. Enumerate each of the filesystem attachments,
// and locate the corresponding unit attachment if any.
// Each filesystem attachment has at most one corresponding
// unit attachment.
for machineId, machineInfo := range info.Attachments.Machines {
filesystemAttachmentInfo := filesystemAttachmentInfo
filesystemAttachmentInfo.MachineId = machineId
filesystemAttachmentInfo.MachineFilesystemAttachment = machineInfo
for unitId, unitInfo := range info.Attachments.Units {
if unitInfo.MachineId == machineId {
filesystemAttachmentInfo.UnitId = unitId
filesystemAttachmentInfo.UnitStorageAttachment = unitInfo
break
}
}
filesystemAttachmentInfos = append(filesystemAttachmentInfos, filesystemAttachmentInfo)
}
}
sort.Sort(filesystemAttachmentInfos)
for _, info := range filesystemAttachmentInfos {
var size string
if info.Size > 0 {
size = humanize.IBytes(info.Size * humanize.MiByte)
}
print(
info.MachineId, info.UnitId, info.Storage,
info.FilesystemId, info.Volume, info.ProviderFilesystemId,
info.MountPoint, size,
string(info.Status.Current), info.Status.Message,
)
}
return tw.Flush()
}
开发者ID:kat-co,项目名称:juju,代码行数:55,代码来源:filesystemlistformatters.go
示例13: formatMetadataTabular
// formatMetadataTabular writes a tabular summary of cloud image metadata.
func formatMetadataTabular(writer io.Writer, metadata []MetadataInfo) {
tw := output.TabWriter(writer)
print := func(values ...string) {
fmt.Fprintln(tw, strings.Join(values, "\t"))
}
print("Source", "Series", "Arch", "Region", "Image id", "Stream", "Virt Type", "Storage Type")
for _, m := range metadata {
print(m.Source, m.Series, m.Arch, m.Region, m.ImageId, m.Stream, m.VirtType, m.RootStorageType)
}
tw.Flush()
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:listformatter.go
示例14: formatDefaultConfigTabular
// formatConfigTabular writes a tabular summary of default config information.
func formatDefaultConfigTabular(writer io.Writer, value interface{}) error {
defaultValues, ok := value.(config.ModelDefaultAttributes)
if !ok {
return errors.Errorf("expected value of type %T, got %T", defaultValues, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
p := func(name string, value config.AttributeDefaultValues) {
var c, d interface{}
switch value.Default {
case nil:
d = "-"
case "":
d = `""`
default:
d = value.Default
}
switch value.Controller {
case nil:
c = "-"
case "":
c = `""`
default:
c = value.Controller
}
w.Println(name, d, c)
for _, region := range value.Regions {
w.Println(" "+region.Name, region.Value, "-")
}
}
var valueNames []string
for name := range defaultValues {
valueNames = append(valueNames, name)
}
sort.Strings(valueNames)
w.Println("Attribute", "Default", "Controller")
for _, name := range valueNames {
info := defaultValues[name]
out := &bytes.Buffer{}
err := cmd.FormatYaml(out, info)
if err != nil {
return errors.Annotatef(err, "formatting value for %q", name)
}
p(name, info)
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:54,代码来源:defaultscommand.go
示例15: FormatMachineTabular
// FormatMachineTabular writes a tabular summary of machine
func FormatMachineTabular(writer io.Writer, forceColor bool, value interface{}) error {
fs, valueConverted := value.(formattedMachineStatus)
if !valueConverted {
return errors.Errorf("expected value of type %T, got %T", fs, value)
}
tw := output.TabWriter(writer)
if forceColor {
tw.SetColorCapable(forceColor)
}
printMachines(tw, fs.Machines)
tw.Flush()
return nil
}
开发者ID:kat-co,项目名称:juju,代码行数:15,代码来源:output_tabular.go
示例16: printTabular
// printTabular prints the list of actions in tabular format
func (c *listCommand) printTabular(writer io.Writer, value interface{}) error {
list, ok := value.([]listOutput)
if !ok {
return errors.New("unexpected value")
}
tw := output.TabWriter(writer)
fmt.Fprintf(tw, "%s\t%s\n", "Action", "Description")
for _, value := range list {
fmt.Fprintf(tw, "%s\t%s\n", value.action, strings.TrimSpace(value.description))
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:list.go
示例17: formatCloudsTabular
// 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
}
开发者ID:bac,项目名称:juju,代码行数:50,代码来源:list.go
示例18: formatWhoAmITabular
func formatWhoAmITabular(writer io.Writer, value interface{}) error {
details, ok := value.(whoAmI)
if !ok {
return errors.Errorf("expected value of type %T, got %T", details, value)
}
tw := output.TabWriter(writer)
fmt.Fprintf(tw, "Controller:\t%s\n", details.ControllerName)
modelName := details.ModelName
if modelName == "" {
modelName = "<no-current-model>"
}
fmt.Fprintf(tw, "Model:\t%s\n", modelName)
fmt.Fprintf(tw, "User:\t%s", details.UserName)
return tw.Flush()
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:whoami.go
示例19: FormatTabularBlockedModels
// FormatTabularBlockedModels writes out tabular format for blocked models.
// This method is exported as it is also used by destroy-model.
func FormatTabularBlockedModels(writer io.Writer, value interface{}) error {
models, ok := value.([]modelBlockInfo)
if !ok {
return errors.Errorf("expected value of type %T, got %T", models, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
w.Println("Name", "Model UUID", "Owner", "Disabled commands")
for _, model := range models {
w.Println(model.Name, model.UUID, model.Owner, strings.Join(model.CommandSets, ", "))
}
tw.Flush()
return nil
}
开发者ID:bac,项目名称:juju,代码行数:17,代码来源:list.go
示例20: formatCredentialsTabular
// formatCredentialsTabular writes a tabular summary of cloud information.
func formatCredentialsTabular(writer io.Writer, value interface{}) error {
credentials, ok := value.(credentialsMap)
if !ok {
return errors.Errorf("expected value of type %T, got %T", credentials, value)
}
if len(credentials.Credentials) == 0 {
fmt.Fprintln(writer, "No credentials to display.")
return nil
}
// For tabular we'll sort alphabetically by cloud, and then by credential name.
var cloudNames []string
for name := range credentials.Credentials {
cloudNames = append(cloudNames, name)
}
sort.Strings(cloudNames)
tw := output.TabWriter(writer)
p := func(values ...string) {
text := strings.Join(values, "\t")
fmt.Fprintln(tw, text)
}
p("CLOUD\tCREDENTIALS")
for _, cloudName := range cloudNames {
var haveDefault bool
var credentialNames []string
credentials := credentials.Credentials[cloudName]
for credentialName := range credentials.Credentials {
if credentialName == credentials.DefaultCredential {
credentialNames = append([]string{credentialName + "*"}, credentialNames...)
haveDefault = true
} else {
credentialNames = append(credentialNames, credentialName)
}
}
if haveDefault {
sort.Strings(credentialNames[1:])
} else {
sort.Strings(credentialNames)
}
p(cloudName, strings.Join(credentialNames, ", "))
}
tw.Flush()
return nil
}
开发者ID:kat-co,项目名称:juju,代码行数:48,代码来源:listcredentials.go
注:本文中的github.com/juju/juju/cmd/output.TabWriter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论