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


Golang cmd.NewTable函数代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.NewTable函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTable函数的具体用法?Golang NewTable怎么用?Golang NewTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: Run

func (c *teamList) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/teams")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	if resp.StatusCode == http.StatusOK {
		defer resp.Body.Close()
		b, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return err
		}
		var teams []teamItem
		err = json.Unmarshal(b, &teams)
		if err != nil {
			return err
		}
		table := cmd.NewTable()
		table.Headers = cmd.Row{"Team", "Permissions"}
		table.LineSeparator = true
		for _, team := range teams {
			table.AddRow(cmd.Row{team.Name, strings.Join(team.Permissions, "\n")})
		}
		fmt.Fprint(context.Stdout, table.String())
	}
	return nil
}
开发者ID:pauloalem,项目名称:tsuru-client,代码行数:34,代码来源:auth.go

示例2: BuildPlansTable

func (c serviceInfo) BuildPlansTable(serviceName string, ctx *cmd.Context, client *cmd.Client) error {
	ctx.Stdout.Write([]byte("\nPlans\n"))
	url, err := cmd.GetURL(fmt.Sprintf("/services/%s/plans", serviceName))
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	var plans []map[string]string
	err = json.Unmarshal(result, &plans)
	if err != nil {
		return err
	}
	if len(plans) > 0 {
		table := cmd.NewTable()
		for _, plan := range plans {
			data := []string{plan["Name"], plan["Description"]}
			table.AddRow(cmd.Row(data))
		}
		table.Headers = cmd.Row([]string{"Name", "Description"})
		ctx.Stdout.Write(table.Bytes())
	}
	return nil
}
开发者ID:dcarley,项目名称:tsuru-client,代码行数:35,代码来源:services.go

示例3: String

func (a *app) String() string {
	format := `Application: {{.Name}}
Repository: {{.Repository}}
Platform: {{.Platform}}
Teams: {{.GetTeams}}
Address: {{.Addr}}
Owner: {{.Owner}}
Team owner: {{.TeamOwner}}
Deploys: {{.Deploys}}
`
	tmpl := template.Must(template.New("app").Parse(format))
	units := cmd.NewTable()
	units.Headers = cmd.Row([]string{"Unit", "State"})
	for _, unit := range a.Units {
		if unit.Name != "" {
			units.AddRow(cmd.Row([]string{unit.Name, unit.Status}))
		}
	}
	var buf bytes.Buffer
	tmpl.Execute(&buf, a)
	var suffix string
	if units.Rows() > 0 {
		suffix = fmt.Sprintf("Units:\n%s", units)
	}
	return buf.String() + suffix
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:26,代码来源:apps.go

示例4: Run

func (c *NodeContainerInfo) Run(context *cmd.Context, client *cmd.Client) error {
	u, err := cmd.GetURL("/docker/nodecontainers/" + context.Args[0])
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", u, nil)
	if err != nil {
		return err
	}
	rsp, err := client.Do(request)
	if err != nil {
		return err
	}
	var poolConfigs map[string]NodeContainerConfig
	err = json.NewDecoder(rsp.Body).Decode(&poolConfigs)
	if err != nil {
		return err
	}
	tbl := cmd.NewTable()
	tbl.LineSeparator = true
	tbl.Headers = cmd.Row{"Pool", "Config"}
	for poolName, config := range poolConfigs {
		data, err := json.MarshalIndent(config, "", "  ")
		if err != nil {
			return err
		}
		if poolName == "" {
			poolName = emptyPoolLabel
		}
		tbl.AddRow(cmd.Row{poolName, string(data)})
	}
	tbl.Sort()
	fmt.Fprint(context.Stdout, tbl.String())
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:35,代码来源:cmd.go

示例5: Show

func (c *appList) Show(result []byte, context *cmd.Context) error {
	var apps []app
	err := json.Unmarshal(result, &apps)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"Application", "Units State Summary", "Address"})
	for _, app := range apps {
		var available int
		var total int
		for _, unit := range app.Units {
			if unit.Name != "" {
				total++
				if unit.Available() {
					available++
				}
			}
		}
		summary := fmt.Sprintf("%d of %d units in-service", available, total)
		addrs := strings.Replace(app.Addr(), ", ", "\n", -1)
		table.AddRow(cmd.Row([]string{app.Name, summary, addrs}))
	}
	table.LineSeparator = true
	table.Sort()
	context.Stdout.Write(table.Bytes())
	return nil
}
开发者ID:dcarley,项目名称:tsuru-client,代码行数:28,代码来源:apps.go

示例6: Run

func (c *machineList) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/iaas/machines")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	var machines []iaas.Machine
	err = json.NewDecoder(response.Body).Decode(&machines)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"Id", "IaaS", "Address", "Creation Params"})
	table.LineSeparator = true
	for _, machine := range machines {
		var params []string
		for k, v := range machine.CreationParams {
			params = append(params, fmt.Sprintf("%s=%s", k, v))
		}
		sort.Strings(params)
		table.AddRow(cmd.Row([]string{machine.Id, machine.Iaas, machine.Address, strings.Join(params, "\n")}))
	}
	table.Sort()
	context.Stdout.Write(table.Bytes())
	return nil
}
开发者ID:combor,项目名称:tsuru-admin,代码行数:33,代码来源:iaas.go

示例7: Run

func (c *listUsers) Run(ctx *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/users")
	if err != nil {
		return err
	}
	request, _ := http.NewRequest("GET", url, nil)
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	var users []user
	err = json.NewDecoder(resp.Body).Decode(&users)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"User", "Teams"})
	for _, u := range users {
		table.AddRow(cmd.Row([]string{u.Email, strings.Join(u.Teams, ", ")}))
	}
	table.LineSeparator = true
	table.Sort()
	ctx.Stdout.Write(table.Bytes())
	return nil
}
开发者ID:combor,项目名称:tsuru-admin,代码行数:26,代码来源:auth.go

示例8: Run

func (c *planRoutersList) Run(context *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/plans/routers")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	var routers []router.PlanRouter
	err = json.NewDecoder(response.Body).Decode(&routers)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"Name", "Type"})
	table.LineSeparator = true
	for _, router := range routers {
		table.AddRow(cmd.Row([]string{router.Name, router.Type}))
	}
	context.Stdout.Write(table.Bytes())
	return nil
}
开发者ID:combor,项目名称:tsuru-admin,代码行数:27,代码来源:plan.go

示例9: Run

func (c *roleList) Run(context *cmd.Context, client *cmd.Client) error {
	addr, err := cmd.GetURL("/roles")
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", addr, nil)
	if err != nil {
		return err
	}
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	result, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return err
	}
	var roles []permission.Role
	err = json.Unmarshal(result, &roles)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row{"Role", "Context", "Permissions"}
	table.LineSeparator = true
	for _, r := range roles {
		table.AddRow(cmd.Row{r.Name, string(r.ContextType), strings.Join(r.SchemeNames, "\n")})
	}
	fmt.Fprint(context.Stdout, table.String())
	return nil
}
开发者ID:pauloalem,项目名称:tsuru-client,代码行数:31,代码来源:permission.go

示例10: BuildInstancesTable

func (c serviceInfo) BuildInstancesTable(serviceName string, ctx *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/services/" + serviceName)
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	var instances []ServiceInstanceModel
	err = json.Unmarshal(result, &instances)
	if err != nil {
		return err
	}
	ctx.Stdout.Write([]byte(fmt.Sprintf("Info for \"%s\"\n\n", serviceName)))
	if len(instances) > 0 {
		ctx.Stdout.Write([]byte("Instances\n"))
		table := cmd.NewTable()
		extraHeaders := c.ExtraHeaders(instances)
		hasPlan := false
		var data []string
		var headers []string
		for _, instance := range instances {
			if instance.PlanName != "" {
				hasPlan = true
			}
		}
		for _, instance := range instances {
			apps := strings.Join(instance.Apps, ", ")
			if hasPlan {
				data = []string{instance.Name, instance.PlanName, apps}
			} else {
				data = []string{instance.Name, apps}
			}
			for _, h := range extraHeaders {
				data = append(data, instance.Info[h])
			}
			table.AddRow(cmd.Row(data))
		}
		if hasPlan {
			headers = []string{"Instances", "Plan", "Apps"}
		} else {
			headers = []string{"Instances", "Apps"}
		}
		headers = append(headers, extraHeaders...)
		table.Headers = cmd.Row(headers)
		ctx.Stdout.Write(table.Bytes())
	}
	return nil
}
开发者ID:pauloalem,项目名称:tsuru-client,代码行数:59,代码来源:services.go

示例11: renderList

func renderList(w io.Writer, permissions []*permissionData) {
	t := cmd.NewTable()
	t.Headers = cmd.Row{"Name", "Contexts"}
	for _, perm := range permissions {
		t.AddRow(cmd.Row{perm.Name, strings.Join(perm.Contexts, ", ")})
	}
	fmt.Fprint(w, t.String())
}
开发者ID:pauloalem,项目名称:tsuru-client,代码行数:8,代码来源:permission.go

示例12: Run

func (*migrationListCmd) Run(context *cmd.Context, client *cmd.Client) error {
	migrations, err := migration.List()
	if err != nil {
		return err
	}
	tbl := cmd.NewTable()
	tbl.Headers = cmd.Row{"Name", "Mandatory?", "Executed?"}
	for _, m := range migrations {
		tbl.AddRow(cmd.Row{m.Name, strconv.FormatBool(!m.Optional), strconv.FormatBool(m.Ran)})
	}
	fmt.Fprint(context.Stdout, tbl.String())
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:13,代码来源:migrate.go

示例13: renderPlans

func renderPlans(plans []tsuruapp.Plan, isBytes bool) string {
	table := cmd.NewTable()
	table.Headers = []string{"Name", "Memory", "Swap", "Cpu Share", "Router", "Default"}
	for _, p := range plans {
		var memory, swap string
		if isBytes {
			memory = fmt.Sprintf("%d", p.Memory)
			swap = fmt.Sprintf("%d", p.Swap)
		} else {
			memory = fmt.Sprintf("%d MB", p.Memory/1024/1024)
			swap = fmt.Sprintf("%d MB", p.Swap/1024/1024)
		}
		table.AddRow([]string{
			p.Name, memory, swap,
			strconv.Itoa(p.CpuShare),
			p.Router,
			strconv.FormatBool(p.Default),
		})
	}
	return table.String()
}
开发者ID:wpjunior,项目名称:tsuru-client,代码行数:21,代码来源:plan.go

示例14: String

func (a *app) String() string {
	format := `Application: %s
Repository: %s
Platform: %s
Teams: %s
Address: %s
Owner: %s
Deploys: %d
`
	teams := strings.Join(a.Teams, ", ")
	units := cmd.NewTable()
	units.Headers = cmd.Row([]string{"Unit", "State"})
	for _, unit := range a.Units {
		if unit.Name != "" {
			units.AddRow(cmd.Row([]string{unit.Name, unit.State}))
		}
	}
	args := []interface{}{a.Name, a.Repository, a.Platform, teams, a.Addr(), a.Owner, a.Deploys}
	if units.Rows() > 0 {
		format += "Units:\n%s"
		args = append(args, units)
	}
	return fmt.Sprintf(format, args...)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:24,代码来源:apps.go

示例15: String

func (a *app) String() string {
	format := `Application: {{.Name}}
Repository: {{.Repository}}
Platform: {{.Platform}}
Teams: {{.GetTeams}}
Address: {{.Addr}}
Owner: {{.Owner}}
Team owner: {{.TeamOwner}}
Deploys: {{.Deploys}}
Pool: {{.Pool}}{{if .Lock.Locked}}
{{.Lock.String}}{{end}}
`
	var buf bytes.Buffer
	tmpl := template.Must(template.New("app").Parse(format))
	unitsByProcess := map[string][]unit{}
	for _, u := range a.Units {
		units := unitsByProcess[u.ProcessName]
		unitsByProcess[u.ProcessName] = append(units, u)
	}
	processes := make([]string, 0, len(unitsByProcess))
	for process := range unitsByProcess {
		processes = append(processes, process)
	}
	sort.Strings(processes)
	titles := []string{"Unit", "State"}
	contMap := map[string]container{}
	if len(a.containers) > 0 {
		for _, cont := range a.containers {
			id := cont.ID
			if len(cont.ID) > 10 {
				id = id[:10]
			}
			contMap[id] = cont
		}
		titles = append(titles, []string{"Host", "Port", "IP"}...)
	}
	for _, process := range processes {
		units := unitsByProcess[process]
		unitsTable := cmd.NewTable()
		unitsTable.Headers = cmd.Row(titles)
		for _, unit := range units {
			if unit.Name == "" {
				continue
			}
			id := unit.Name
			if len(unit.Name) > 10 {
				id = id[:10]
			}
			row := []string{id, unit.Status}
			cont, ok := contMap[id]
			if ok {
				row = append(row, []string{cont.HostAddr, cont.HostPort, cont.IP}...)
			}
			unitsTable.AddRow(cmd.Row(row))
		}
		if unitsTable.Rows() > 0 {
			if len(a.containers) > 0 {
				unitsTable.SortByColumn(2)
			}
			buf.WriteString("\n")
			processStr := ""
			if process != "" {
				processStr = fmt.Sprintf(" [%s]", process)
			}
			buf.WriteString(fmt.Sprintf("Units%s: %d\n", processStr, unitsTable.Rows()))
			buf.WriteString(unitsTable.String())
		}
	}
	servicesTable := cmd.NewTable()
	servicesTable.Headers = []string{"Service", "Instance"}
	for _, service := range a.services {
		if len(service.Instances) == 0 {
			continue
		}
		servicesTable.AddRow([]string{service.Service, strings.Join(service.Instances, ", ")})
	}
	if servicesTable.Rows() > 0 {
		buf.WriteString("\n")
		buf.WriteString(fmt.Sprintf("Service instances: %d\n", servicesTable.Rows()))
		buf.WriteString(servicesTable.String())
	}
	if a.Plan.Name != "" {
		buf.WriteString("\n")
		buf.WriteString("App Plan:\n")
		buf.WriteString(renderPlans([]tsuruapp.Plan{a.Plan}, true))
	}
	var tplBuffer bytes.Buffer
	tmpl.Execute(&tplBuffer, a)
	return tplBuffer.String() + buf.String()
}
开发者ID:dcarley,项目名称:tsuru-client,代码行数:90,代码来源:apps.go


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