当前位置: 首页>>代码示例>>Golang>>正文


Golang Writer.Flush方法代码示例

本文整理汇总了Golang中text/tabwriter.Writer.Flush方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.Flush方法的具体用法?Golang Writer.Flush怎么用?Golang Writer.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在text/tabwriter.Writer的用法示例。


在下文中一共展示了Writer.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: run

func (r *releasesCmd) run(e *env, c *client) error {
	u := &url.URL{
		Path: "releases",
	}
	var releasesList []releasesResponse
	if _, err := e.Client.Get(u, &releasesList); err != nil {
		return stackerr.Wrap(err)
	}

	if r.version != "" {
		return r.printFiles(r.version, releasesList, e)
	}

	w := new(tabwriter.Writer)
	w.Init(e.Out, 32, 8, 0, ' ', 0)
	fmt.Fprintln(w, "Name\tDescription\tDate")
	for _, release := range releasesList {
		description := "No release notes given"
		if release.Description != "" {
			description = release.Description
		}
		fmt.Fprintf(w, "%s\t%s\t%s\n", release.Version, description, release.Timestamp)
	}
	w.Flush()
	return nil
}
开发者ID:WilliamRen,项目名称:parse-cli,代码行数:26,代码来源:releases_cmd.go

示例2: print

func (a analytics) print() {
	glog.Infof("Made %d API calls since the last Reset %f calls/sec", a.apiCount, a.apiPerSec)

	buf := new(bytes.Buffer)
	w := new(tabwriter.Writer)
	w.Init(buf, 0, 0, 1, ' ', tabwriter.AlignRight)
	fmt.Fprintf(w, "AddLabels\t%d\t\n", a.AddLabels.Count)
	fmt.Fprintf(w, "RemoveLabels\t%d\t\n", a.RemoveLabels.Count)
	fmt.Fprintf(w, "ListCollaborators\t%d\t\n", a.ListCollaborators.Count)
	fmt.Fprintf(w, "GetIssue\t%d\t\n", a.GetIssue.Count)
	fmt.Fprintf(w, "ListIssues\t%d\t\n", a.ListIssues.Count)
	fmt.Fprintf(w, "ListIssueEvents\t%d\t\n", a.ListIssueEvents.Count)
	fmt.Fprintf(w, "ListCommits\t%d\t\n", a.ListCommits.Count)
	fmt.Fprintf(w, "GetCommit\t%d\t\n", a.GetCommit.Count)
	fmt.Fprintf(w, "GetCombinedStatus\t%d\t\n", a.GetCombinedStatus.Count)
	fmt.Fprintf(w, "SetStatus\t%d\t\n", a.SetStatus.Count)
	fmt.Fprintf(w, "GetPR\t%d\t\n", a.GetPR.Count)
	fmt.Fprintf(w, "AssignPR\t%d\t\n", a.AssignPR.Count)
	fmt.Fprintf(w, "ClosePR\t%d\t\n", a.ClosePR.Count)
	fmt.Fprintf(w, "OpenPR\t%d\t\n", a.OpenPR.Count)
	fmt.Fprintf(w, "GetContents\t%d\t\n", a.GetContents.Count)
	fmt.Fprintf(w, "ListComments\t%d\t\n", a.ListComments.Count)
	fmt.Fprintf(w, "CreateComment\t%d\t\n", a.CreateComment.Count)
	fmt.Fprintf(w, "DeleteComment\t%d\t\n", a.DeleteComment.Count)
	fmt.Fprintf(w, "Merge\t%d\t\n", a.Merge.Count)
	fmt.Fprintf(w, "GetUser\t%d\t\n", a.GetUser.Count)
	fmt.Fprintf(w, "SetMilestone\t%d\t\n", a.SetMilestone.Count)
	fmt.Fprintf(w, "ListMilestones\t%d\t\n", a.ListMilestones.Count)
	w.Flush()
	glog.V(2).Infof("\n%v", buf)
}
开发者ID:timstclair,项目名称:kube-contrib,代码行数:31,代码来源:github.go

示例3: enumerate

func (c *clusterClient) enumerate(context *cli.Context) {
	c.clusterOptions(context)
	jsonOut := context.GlobalBool("json")
	outFd := os.Stdout
	fn := "enumerate"

	cluster, err := c.manager.Enumerate()
	if err != nil {
		cmdError(context, fn, err)
		return
	}

	if jsonOut {
		fmtOutput(context, &Format{Cluster: &cluster})
	} else {
		w := new(tabwriter.Writer)
		w.Init(outFd, 12, 12, 1, ' ', 0)

		fmt.Fprintln(w, "ID\t IMAGE\t STATUS\t NAMES\t NODE")
		for _, n := range cluster.Nodes {
			for _, c := range n.Containers {
				fmt.Fprintln(w, c.ID, "\t", c.Image, "\t", c.Status, "\t",
					c.Names, "\t", n.Ip)
			}
		}

		fmt.Fprintln(w)
		w.Flush()
	}
}
开发者ID:mike6350,项目名称:openstorage,代码行数:30,代码来源:cluster.go

示例4: runLogins

func runLogins(cmd *Command, args []string) {
	active, _ := ActiveLogin()
	accounts, _ := Config.List("accounts")
	if len(accounts) == 0 {
		fmt.Println("no logins")
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 1, 0, 1, ' ', 0)

		for _, account := range accounts {
			if !strings.HasPrefix(account, ".") {
				var creds ForceCredentials
				data, err := Config.Load("accounts", account)
				json.Unmarshal([]byte(data), &creds)

				if err != nil {
					return
				}

				var banner = fmt.Sprintf("\t%s", creds.InstanceUrl)
				if account == active {
					account = fmt.Sprintf("\x1b[31;1m%s (active)\x1b[0m", account)
				} else {
					account = fmt.Sprintf("%s \x1b[31;1m\x1b[0m", account)
				}
				fmt.Fprintln(w, fmt.Sprintf("%s%s", account, banner))
			}
		}
		fmt.Fprintln(w)
		w.Flush()
	}

}
开发者ID:adamlincoln,项目名称:force,代码行数:33,代码来源:logins.go

示例5: printCommandPrefixHelp

func printCommandPrefixHelp(ctx cli.Context, prefix ...string) {
	handler := getHandler(ctx.Handlers(), prefix)

	if handler == nil {
		ExitF("Command not found")
	}

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 0, 3, ' ', 0)

	fmt.Fprintf(w, "%s\n", handler.Description)
	fmt.Fprintf(w, "%s %s\n", Name, handler.Pattern)
	for _, group := range handler.FlagGroups {
		fmt.Fprintf(w, "\n%s:\n", group.Name)
		for _, flag := range group.Flags {
			boolFlag, isBool := flag.(cli.BoolFlag)
			if isBool && boolFlag.OmitValue {
				fmt.Fprintf(w, "  %s\t%s\n", strings.Join(flag.GetPatterns(), ", "), flag.GetDescription())
			} else {
				fmt.Fprintf(w, "  %s <%s>\t%s\n", strings.Join(flag.GetPatterns(), ", "), flag.GetName(), flag.GetDescription())
			}
		}
	}

	w.Flush()
}
开发者ID:RandomArray,项目名称:gdrive,代码行数:26,代码来源:handlers_meta.go

示例6: main

func main() {
	multicall.Add("acbuild-script", func() error {
		cmd := exec.Command("acbuild", append([]string{"script"}, os.Args[1:]...)...)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		return cmd.Run()
	})
	// check if acbuild is executed with a multicall command
	multicall.MaybeExec()

	cmdAcbuild.SetUsageFunc(func(cmd *cobra.Command) error {
		tabOut := new(tabwriter.Writer)
		tabOut.Init(os.Stdout, 0, 8, 1, '\t', 0)
		commandUsageTemplate.Execute(tabOut, cmd)
		tabOut.Flush()
		return nil
	})

	// Make help just show the usage
	cmdAcbuild.SetHelpTemplate(`{{.UsageString}}`)

	err := cmdAcbuild.Execute()
	if cmdExitCode == 0 && err != nil {
		cmdExitCode = getErrorCode(errCobra)
	}
	os.Exit(cmdExitCode)
}
开发者ID:dgonyeo,项目名称:acbuild,代码行数:28,代码来源:acbuild.go

示例7: help

func help() {
	w := new(tabwriter.Writer)
	w.Init(os.Stderr, 4, 0, 2, ' ', 0)
	av0 := path.Base(os.Args[0])

	fmt.Fprintf(w, "Linux Tao Host\n")
	fmt.Fprintf(w, "Usage:\n")
	fmt.Fprintf(w, "  %s init [options]\t Initialize a new host\n", av0)
	fmt.Fprintf(w, "  %s show [options]\t Show host principal name\n", av0)
	fmt.Fprintf(w, "  %s start [options]\t Start the host\n", av0)
	fmt.Fprintf(w, "  %s stop [options]\t Request the host stop\n", av0)
	fmt.Fprintf(w, "\n")

	categories := []options.Category{
		{"all", "Basic options for most commands"},
		{"init", "Options for 'init' command"},
		{"start", "Options for 'start' command"},
		{"root", "Options for root hosts"},
		{"stacked", "Options for stacked hosts"},
		{"kvm", "Options for hosting QEMU/KVM CoreOS"},
		{"logging", "Options to control log output"},
	}
	options.ShowRelevant(w, categories...)

	w.Flush()
}
开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:26,代码来源:host.go

示例8: formatOutput

func formatOutput(s Stock) {
	w := new(tabwriter.Writer)

	w.Init(os.Stdout, 0, 8, 1, '\t', 0)

	fmt.Print("\033[2J\033[H")

	fmt.Fprintln(w, time.Now().Round(time.Second).String())

	var d Data
	v := reflect.ValueOf(d) // reflect lets us iterate on the struct

	var value, separator, header string

	for i := 0; i < v.NumField(); i++ {
		value = v.Type().Field(i).Name
		if i < (v.NumField() - 1) {
			separator = "\t"
		} else {
			separator = ""
		}

		// Print the header labels underlined
		header += fmt.Sprintf("\033[4m%s\033[0m%s", value, separator)
	}

	fmt.Fprintln(w, header)

	// run the stock through String()
	for _, stock := range s.Data {
		fmt.Fprintln(w, stock)
	}

	w.Flush()
}
开发者ID:investislife,项目名称:gostock-1,代码行数:35,代码来源:gostock.go

示例9: String

func (d *dhcp) String() string {
	var o bytes.Buffer

	w := new(tabwriter.Writer)
	w.Init(&o, 5, 0, 1, ' ', 0)

	fmt.Fprintf(w, "Listen address:\t%v\n", d.addr)
	fmt.Fprintf(w, "Low address:\t%v\n", d.low)
	fmt.Fprintf(w, "High address:\t%v\n", d.high)
	fmt.Fprintf(w, "Router:\t%v\n", d.router)
	fmt.Fprintf(w, "DNS:\t%v\n", d.dns)
	fmt.Fprintf(w, "Static IPs:\t\n")
	w.Flush()

	w = new(tabwriter.Writer)
	w.Init(&o, 5, 0, 1, ' ', 0)

	var keys []string
	for k, _ := range d.static {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, mac := range keys {
		ip := d.static[mac]
		fmt.Fprintf(w, "\t%v\t%v\n", mac, ip)
	}
	w.Flush()

	return o.String()
}
开发者ID:cdshann,项目名称:minimega,代码行数:30,代码来源:router.go

示例10: selectHerokuApp

func selectHerokuApp(apps nameIDs, e *parsecli.Env) (*nameID, error) {
	fmt.Fprintf(e.Out, "Please select from the following Heroku apps: (Enter a number between 1 and %d)\n", len(apps))
	for i, app := range apps {
		w := new(tabwriter.Writer)
		w.Init(e.Out, 0, 8, 0, '\t', 0)
		fmt.Fprintf(w, "%d: %s\t\t(%s)\n", i+1, app.name, app.id)
		if err := w.Flush(); err != nil {
			return nil, stackerr.Wrap(err)
		}
	}
	fmt.Fprintf(e.Out, "Selection: ")
	var selection string
	fmt.Fscanf(e.In, "%s\n", &selection)

	n, err := strconv.Atoi(selection)
	if err != nil {
		return nil, err
	}

	lapps := len(apps)
	if n <= 0 || n > lapps {
		return nil, stackerr.Newf("Invalid selection: can only be in range 1..%d", lapps)
	}
	return &apps[n-1], nil
}
开发者ID:jinkawin,项目名称:parse-cli,代码行数:25,代码来源:add.go

示例11: printTaskList

// Prints out the output of tasks
func printTaskList(taskList []photon.Task, c *cli.Context) error {
	if c.GlobalIsSet("non-interactive") {
		for _, task := range taskList {
			fmt.Printf("%s\t%s\t%s\t%d\t%d\n", task.ID, task.State, task.Operation, task.StartedTime, task.EndTime-task.StartedTime)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(taskList, os.Stdout, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "\nTask\tStart Time\tDuration\n")

		for _, task := range taskList {
			var duration int64
			startTime := timestampToString(task.StartedTime)
			if task.EndTime-task.StartedTime > 0 {
				duration = (task.EndTime - task.StartedTime) / 1000
			} else {
				duration = 0
			}
			fmt.Fprintf(w, "%s\t%s\t%.2d:%.2d:%.2d\n", task.ID, startTime, duration/3600, (duration/60)%60, duration%60)
			err := w.Flush()
			if err != nil {
				return err
			}
			fmt.Printf("%s, %s\n", task.Operation, task.State)
		}
		if len(taskList) > 0 {
			fmt.Printf("\nYou can run 'photon task show <id>' for more information\n")
		}
		fmt.Printf("Total: %d\n", len(taskList))
	}

	return nil
}
开发者ID:vmware,项目名称:photon-controller-cli,代码行数:36,代码来源:iohelpers.go

示例12: formatDNSRecords

// formatDNSRecords takes a list of DNS records and formats them as a table.
func formatDNSRecords(records []dnsimple.Record, domainName string) string {
	buf := new(bytes.Buffer)

	// initialize the tabwriter
	w := new(tabwriter.Writer)
	minWidth := 0
	tabWidth := 8
	padding := 3
	w.Init(buf, minWidth, tabWidth, padding, ' ', 0)

	for index, record := range records {

		// assemble the subdomain / domain name
		domainName := domainName
		if !isEmpty(record.Name) {
			domainName = record.Name + "." + domainName
		}

		fmt.Fprintf(w, "%s\t%s\t%s", domainName, record.RecordType, record.Content)

		// append newline if we are not
		// formatting the last record
		if index < len(records)-1 {
			fmt.Fprintf(w, "\n")
		}

	}

	w.Flush()

	return buf.String()
}
开发者ID:andreaskoch,项目名称:dee-cli,代码行数:33,代码来源:actionlist.go

示例13: printNodesets

func (c *RollingUpdateClusterCmd) printNodesets(nodesets map[string]*kutil.Nodeset) error {
	w := new(tabwriter.Writer)
	var b bytes.Buffer

	// Format in tab-separated columns with a tab stop of 8.
	w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
	for _, n := range nodesets {
		b.WriteByte(tabwriter.Escape)
		b.WriteString(n.Name)
		b.WriteByte(tabwriter.Escape)
		b.WriteByte('\t')
		b.WriteByte(tabwriter.Escape)
		b.WriteString(n.Status)
		b.WriteByte(tabwriter.Escape)
		b.WriteByte('\t')
		b.WriteByte(tabwriter.Escape)
		b.WriteString(fmt.Sprintf("%d", len(n.NeedUpdate)))
		b.WriteByte(tabwriter.Escape)
		b.WriteByte('\t')
		b.WriteByte(tabwriter.Escape)
		b.WriteString(fmt.Sprintf("%d", len(n.Ready)))
		b.WriteByte(tabwriter.Escape)
		b.WriteByte('\n')

		_, err := w.Write(b.Bytes())
		if err != nil {
			return fmt.Errorf("error writing to output: %v", err)
		}
		b.Reset()
	}

	return w.Flush()
}
开发者ID:crohling,项目名称:kops,代码行数:33,代码来源:rollingupdate_cluster.go

示例14: GenerateReport

//Given a Certificates list, create a tabular report of
//the relevant information in string format
func GenerateReport(certs CertificateInfoList, warningsOnly bool) string {
	sort.Sort(certs)
	pReader, pWriter := io.Pipe()
	var buff bytes.Buffer
	reportWriter := new(tabwriter.Writer)
	reportWriter.Init(pWriter, 0, 8, 0, '\t', 0)
	fmt.Fprintln(reportWriter, "Site\tCommon Name\tStatus\t   \tDays Left\tExpire Date")
	expiredCount := 0
	for _, cert := range certs {
		if cert != nil {
			eDate := cert.cert.NotAfter
			var expired string
			if IsExpired(eDate) {
				expired = "Expired"
				expiredCount++
			} else {
				expired = "Valid"
			}
			daysToExpire := GetExpireDays(eDate)
			cn := cert.cert.Subject.CommonName
			if (warningsOnly && IsExpired(eDate)) || !warningsOnly {
				fmt.Fprintf(reportWriter, "%s\t%s\t%s\t   \t%d\t%s\n", cert.name, cn, expired, daysToExpire, eDate.Local())
			}
		}
	}
	if expiredCount == 0 && warningsOnly {
		return ""
	}
	go buff.ReadFrom(pReader)
	reportWriter.Flush()
	pWriter.Close()
	pReader.Close()
	return buff.String()
}
开发者ID:rossdylan,项目名称:sslcheck,代码行数:36,代码来源:sslcheck.go

示例15: printConns

func printConns(w *tabwriter.Writer, comps map[string]*Component) {
	var keys sort.IntSlice

	for refdes := range comps {
		m := connRefdesRegexp.FindStringSubmatch(refdes)
		if m != nil {
			n, _ := strconv.ParseInt(m[1], 10, 0)
			keys = append(keys, int(n))
		}
	}

	if len(keys) > 0 {
		sort.Sort(keys)

		fmt.Fprintf(w, "##### Connectors #####\n\n")
		w.Flush()

		fmt.Fprintf(w, "REFDES\tDEVICE\tFOOTPRINT\tAPPLICATION DESCRIPTION\n")

		for _, n := range keys {
			refdes := fmt.Sprintf("CONN%d", n)
			comp := comps[refdes]
			//comp.loadSymAttrs()

			fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", refdes, comp.attrs["device"], comp.attrs["footprint"], comp.attrs["x-appdesc"])

			delete(comps, refdes)
		}

		fmt.Fprintf(w, "\n\n")
		w.Flush()
	}
}
开发者ID:kierdavis,项目名称:k12,代码行数:33,代码来源:partlist.go


注:本文中的text/tabwriter.Writer.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。