Example #1
0
File: list.go Project: grrtrr/clcv2
func main() {
	var links = flag.Bool("l", false, "List the Link References as well")

	flag.Parse()

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	datacenters, err := client.GetLocations()
	if err != nil {
		exit.Fatalf("failed to get datacenter information: %s", err)
	}

	if *links {
		for _, ctr := range datacenters {
			fmt.Println("\n", ctr.Name)

			table := tablewriter.NewWriter(os.Stdout)
			table.SetAutoFormatHeaders(false)
			table.SetAlignment(tablewriter.ALIGN_LEFT)
			table.SetAutoWrapText(false)

			// See https://www.ctl.io/api-docs/v2/#getting-started-api-v20-links-framework
			table.SetHeader([]string{"Rel", "Href", "Verbs"})
			for _, link := range ctr.Links {
				var verbs string

				if len(link.Verbs) == 0 {
					verbs = "GET"
				} else {
					verbs = strings.Join(link.Verbs, ", ")
				}
				table.Append([]string{link.Rel, link.Href, verbs})
			}
			table.Render()
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)
		table.SetHeader([]string{"Id", "Name"})

		for _, ctr := range datacenters {
			table.Append([]string{ctr.Id, ctr.Name})
		}
		table.Render()
	}
}
Example #2
0
func actionStatus(c *cli.Context) {
	err, profile := loadProfile(c, true)
	if err != nil {
		panic(err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Id", "Name", "Cert", "Type", "URL"})

	maxCacheAge := profile.MaxCacheAge
	if c.GlobalBool("flushCache") == true {
		maxCacheAge = 0
	}

	err, instances := getInstances(profile.Region, maxCacheAge, profile)
	if err != nil {
		panic(err)
	}

	for _, instance := range instances {
		table.Append([]string{
			instance.Id, instance.Name,
			instance.CertName, instance.InstanceType,
			instance.PublicDnsName,
		})
	}

	table.Render()
}
Example #3
0
// Print (pointer) to struct as table, using key/type/value
func PrintStruct(in interface{}) {
	t := reflect.TypeOf(in)
	v := reflect.ValueOf(in)

	if in == nil {
		fmt.Println("nil")
		return
	}

	if t.Kind() == reflect.Ptr {
		t = t.Elem()
		v = reflect.Indirect(v)
	}

	if t.Kind() != reflect.Struct {
		panic(fmt.Errorf("Expected a struct, got %T", in))
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(false)

	table.SetHeader([]string{t.Name(), "Type", "Value"})
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		table.Append([]string{f.Name, f.Type.Name(), fmt.Sprintf("%v", v.Field(i))})
	}
	table.Render()
}
Example #4
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	top, err := client.GetHistory(*projectid)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		for _, data := range top.Events {
			var job string
			if data.Job != nil {
				job = data.Job.ID
			} else {
				job = "<adhoc>"
			}
			table.SetHeader([]string{"Status", "Summary", "Start Time", "End Time", "S/F/T", "Job", "Execution", "User", "Project"})
			table.Append([]string{
				data.Status,
				data.Summary,
				data.StartTime,
				data.EndTime,
				fmt.Sprintf("%d/%d/%d", data.NodeSummary.Succeeded, data.NodeSummary.Failed, data.NodeSummary.Total),
				job,
				fmt.Sprintf("%d", data.Execution.ID),
				data.User,
				data.Project,
			})
		}
		table.Render()
	}
}
Example #5
0
File: image.go Project: achanda/lxd
func showImages(images []shared.ImageInfo) error {
	data := [][]string{}
	for _, image := range images {
		shortest := shortestAlias(image.Aliases)
		if len(image.Aliases) > 1 {
			shortest = fmt.Sprintf(gettext.Gettext("%s (%d more)"), shortest, len(image.Aliases)-1)
		}
		fp := image.Fingerprint[0:12]
		public := gettext.Gettext("no")
		description := findDescription(image.Properties)
		if shared.InterfaceToBool(image.Public) {
			public = gettext.Gettext("yes")
		}
		const layout = "Jan 2, 2006 at 3:04pm (MST)"
		uploaded := time.Unix(image.UploadDate, 0).Format(layout)
		arch, _ := shared.ArchitectureName(image.Architecture)
		data = append(data, []string{shortest, fp, public, description, arch, uploaded})
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetColWidth(50)
	table.SetHeader([]string{
		gettext.Gettext("ALIAS"),
		gettext.Gettext("FINGERPRINT"),
		gettext.Gettext("PUBLIC"),
		gettext.Gettext("DESCRIPTION"),
		gettext.Gettext("ARCH"),
		gettext.Gettext("UPLOAD DATE")})
	sort.Sort(ByName(data))
	table.AppendBulk(data)
	table.Render()

	return nil
}
Example #6
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	data, err := client.GetRepos(*kind)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{
			"Key",
			"Type",
			"Description",
			"Url",
		})
		for _, r := range data {
			table.Append([]string{
				r.Key,
				r.Rtype,
				r.Description,
				r.Url,
			})
		}
		table.Render()
		os.Exit(0)
	}
}
Example #7
0
func (this *Verify) showTable() {
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"AppId", "PubSub Topic", "Desc", "Kafka Topic", "?"})

	for _, t := range this.topics {
		kafkaTopic := t.KafkaTopicName
		if kafkaTopic == "" {
			// try find its counterpart in raw kafka
			var q *dbx.Query
			if _, present := this.kafkaTopics[t.TopicName]; present {
				kafkaTopic = "[" + t.TopicName + "]"

				q = this.db.NewQuery(fmt.Sprintf("UPDATE topics SET KafkaTopicName='%s' WHERE TopicId=%s",
					t.TopicName, t.TopicId))
				this.Ui.Output(q.SQL())
			}

			if q != nil && this.confirmed {
				_, err := q.Execute()
				swallow(err)
			}
		}

		problem := "N"
		if _, present := this.problemeticTopics[kafkaTopic]; present {
			problem = color.Yellow("Y")
		}

		table.Append([]string{t.AppId, t.TopicName, t.TopicIntro, kafkaTopic, problem})
	}

	table.Render()
}
Example #8
0
func CmdList(is ISites, iservices services.IServices) error {
	serviceProxy, err := iservices.RetrieveByLabel("service_proxy")
	if err != nil {
		return err
	}
	sites, err := is.List(serviceProxy.ID)
	if err != nil {
		return err
	}
	if sites == nil || len(*sites) == 0 {
		logrus.Println("No sites found")
		return nil
	}
	svcs, err := iservices.List()
	svcMap := map[string]string{}
	for _, s := range *svcs {
		svcMap[s.ID] = s.Label
	}

	data := [][]string{{"NAME", "CERT", "UPSTREAM SERVICE"}}
	for _, s := range *sites {
		data = append(data, []string{s.Name, s.Cert, svcMap[s.UpstreamService]})
	}

	table := tablewriter.NewWriter(logrus.StandardLogger().Out)
	table.SetBorder(false)
	table.SetRowLine(false)
	table.SetCenterSeparator("")
	table.SetColumnSeparator("")
	table.SetRowSeparator("")
	table.AppendBulk(data)
	table.Render()
	return nil
}
Example #9
0
func InspectGit(root string) {
	if _, err := os.Stat(root); err == nil {
		fmt.Printf("Inspecting system for git repos at '%v'...\n", root)

		gitRepos := make(map[string]GitRepo)
		findGitRepositories(root, gitRepos)
		if len(gitRepos) >= 0 {
			keys := make([]string, len(gitRepos))
			i := 0
			for key := range gitRepos {
				keys[i] = key
				i++
			}
			sort.Strings(keys)

			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{"Name", "Branch", "Status", "Path"})

			for i := range keys {
				repo := gitRepos[keys[i]]
				v := []string{repo.name, repo.branch, repo.status, repo.path}
				table.Append(v)
			}
			table.Render()
		} else {
			fmt.Printf("No repos found")
		}
	} else {
		if os.IsNotExist(err) {
			fmt.Printf("Directory '%v' does not exist\n", root)
			os.Exit(1)
		}
	}
}
Example #10
0
func WriteTable(groups []*dal.PingGroup) {
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{
		"Time",
		"min",
		"avg",
		"max",
		"std dev",
		"Received",
		"Lost",
	})

	table.SetBorder(false) // Set Border to false
	table.SetAlignment(tablewriter.ALIGN_RIGHT)

	for _, g := range groups {
		row := []string{
			fmt.Sprintf("%s", g.Start.In(time.Local).Format(tableTimeFmt)),
			fmt.Sprintf("%.0f ms", g.MinTime),
			fmt.Sprintf("%.0f ms", g.AvgTime),
			fmt.Sprintf("%.0f ms", g.MaxTime),
			fmt.Sprintf("%.0f ms", g.StdDev),
			fmt.Sprintf("%d", g.Received),
			fmt.Sprintf("%d", g.Timedout),
		}
		table.Append(row)
	}
	table.Render()
}
Example #11
0
File: list.go Project: ch3lo/yale
func listCmd(c *cli.Context) {
	data := [][]string{}
	stackMap, err := stackManager.SearchContainers(c.String("if"), c.String("tf"), c.String("cf"))
	if err != nil {
		util.Log.Fatalln(err)
	}

	for stackKey, containers := range stackMap {
		for _, c := range containers {
			var ports string
			for key, val := range c.PublicPorts() {
				ports = ports + strconv.FormatInt(val, 10) + "->" + strconv.FormatInt(key, 10) + " "
			}
			data = append(data, []string{stackKey, c.ContainerSwarmNode(), c.ContainerName(), c.ContainerImageName(), c.ContainerState(), ports})
		}
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Stack", "Node", "Name", "Image", "Status", "Ports"})

	for _, v := range data {
		table.Append(v)
	}
	table.Render()
}
Example #12
0
func renderInstanceTable(project_id string, instances []*compute.Instance) []byte {
	var buf bytes.Buffer
	table := tablewriter.NewWriter(&buf)
	if project_id == "" {
		table.SetHeader([]string{"PROJECT", "NAME", "ZONE", "MACHINE_TYPE", "INTERNAL_IP", "EXTERNAL_IP", "STATUS"})
	} else {
		table.SetHeader([]string{"NAME", "ZONE", "MACHINE_TYPE", "INTERNAL_IP", "EXTERNAL_IP", "STATUS"})
	}
	for _, ins := range instances {
		p := (func(selflink string) string {
			return strings.Split(strings.Split(selflink, "https://www.googleapis.com/compute/v1/projects/")[1], "/")[0]
		})(ins.SelfLink)
		zone := (func(a []string) string { return a[len(a)-1] })(strings.Split(ins.Zone, "/"))
		machine_type := (func(a []string) string { return a[len(a)-1] })(strings.Split(ins.MachineType, "/"))
		internal_ip := ins.NetworkInterfaces[0].NetworkIP
		external_ip := ins.NetworkInterfaces[0].AccessConfigs[0].NatIP
		var row []string
		if project_id == "" {
			row = []string{p, ins.Name, zone, machine_type, internal_ip, external_ip, ins.Status}
			table.Append(row)
		} else {
			if project_id == p {
				row = []string{ins.Name, zone, machine_type, internal_ip, external_ip, ins.Status}
				table.Append(row)
			}
		}
	}
	table.Render()

	return buf.Bytes()
}
Example #13
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Account-Policy-ID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(0)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	p, err := client.SBSgetPolicy(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to list SBS account policy %s: %s", flag.Arg(0), err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(false)
	table.SetHeader([]string{"Name", "Policy ID", "OS", "Status", "Freq/h", "Ret/d", "Paths"})

	table.Append([]string{p.Name, p.PolicyID, p.OsType, p.Status, fmt.Sprint(p.BackupIntervalHours),
		fmt.Sprint(p.RetentionDays), strings.Join(p.Paths, ", ")})
	table.Render()
}
Example #14
0
// Display project details
// http://docs.gemnasium.apiary.io/#get-%2Fprojects%2F%7Bslug%7D
func (p *Project) Show() error {
	err := p.Fetch()
	if err != nil {
		return err
	}
	if config.RawFormat {
		return nil
	}

	color.Println(fmt.Sprintf("%s: %s\n", p.Name, utils.StatusDots(p.Color)))
	table := tablewriter.NewWriter(os.Stdout)
	table.SetRowLine(true)

	table.Append([]string{"Slug", p.Slug})
	table.Append([]string{"Description", p.Description})
	table.Append([]string{"Origin", p.Origin})
	table.Append([]string{"Private", strconv.FormatBool(p.Private)})
	table.Append([]string{"Monitored", strconv.FormatBool(p.Monitored)})
	if !p.Monitored {
		table.Append([]string{"Unmonitored reason", p.UnmonitoredReason})
	}

	table.Render()
	return nil
}
Example #15
0
File: tuf.go Project: runcom/notary
// Given a list of KeyStores in order of listing preference, pretty-prints the
// root keys and then the signing keys.
func prettyPrintTargets(ts []*notaryclient.Target, writer io.Writer) {
	if len(ts) == 0 {
		writer.Write([]byte("\nNo targets present in this repository.\n\n"))
		return
	}

	sort.Stable(targetsSorter(ts))

	table := tablewriter.NewWriter(writer)
	table.SetHeader([]string{"Name", "Digest", "Size (bytes)"})
	table.SetBorder(false)
	table.SetColumnSeparator(" ")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetCenterSeparator("-")
	table.SetAutoWrapText(false)

	for _, t := range ts {
		table.Append([]string{
			t.Name,
			hex.EncodeToString(t.Hashes["sha256"]),
			fmt.Sprintf("%d", t.Length),
		})
	}
	table.Render()
}
Example #16
0
func main() {
	svc := ec2.New(session.New(), &aws.Config{Region: aws.String("sa-east-1")})
	resp, err := svc.DescribeInstances(nil)
	if err != nil {
		panic(err)
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Tag Name", "Instance Id", "Instance Type", "AZ", "IP", "Status"})

	for _, res := range resp.Reservations {
		for _, instance := range res.Instances {
			var tag_name string
			for _, tag := range instance.Tags {
				if *tag.Key == "Name" {
					tag_name = *tag.Value
				}
			}
			table.Append([]string{
				tag_name,
				*instance.InstanceId,
				*instance.InstanceType,
				*instance.Placement.AvailabilityZone,
				*instance.PrivateIpAddress,
				*instance.State.Name,
			})

		}
	}
	table.Render()

}
Example #17
0
func (gohanClientCLI *GohanClientCLI) createResourcesTable(buffer *bytes.Buffer, resources []interface{}) {
	table := tablewriter.NewWriter(buffer)
	allKeysResource := map[string]interface{}{}
	for _, resource := range resources {
		for key := range resource.(map[string]interface{}) {
			allKeysResource[key] = ""
		}
	}
	keys := util.GetSortedKeys(allKeysResource)
	if len(keys) == 0 {
		return
	}
	table.SetHeader(keys)
	for _, resource := range resources {
		resourceSlice := []string{}
		for _, key := range keys {
			v := ""
			if val, ok := resource.(map[string]interface{})[key]; ok {
				v = fmt.Sprint(val)
			}
			resourceSlice = append(resourceSlice, v)
		}
		table.Append(resourceSlice)
	}
	table.Render()
}
Example #18
0
func writeTable(groups []*PingGroup) {
	fmt.Println("\n")

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{
		"Time",
		"min",
		"avg",
		"max",
		"std dev",
		"Received",
		"Lost",
	})

	table.SetBorder(false) // Set Border to false
	table.SetAlignment(tablewriter.ALIGN_RIGHT)

	l := time.Now().Location()

	for _, g := range groups {
		row := []string{
			fmt.Sprintf("%s", g.Start.In(l).Format("01/02 03:04pm")),
			fmt.Sprintf("%.0f ms", g.MinTime),
			fmt.Sprintf("%.0f ms", g.AvgTime),
			fmt.Sprintf("%.0f ms", g.MaxTime),
			fmt.Sprintf("%.0f ms", g.StdDev),
			fmt.Sprintf("%d", g.Received),
			"0",
		}
		table.Append(row)
	}
	table.Render()
}
Example #19
0
func scoreboardShow(db *sql.DB) {
	res, err := scoreboard.CollectLastResult(db)
	if err != nil {
		log.Fatalln("Get last result fail:", err)
	}

	scoreboard.CountScoreAndSort(&res)

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Rank", "Name", "Score", "Attack",
		"Defence", "Advisory"})

	for _, tr := range res.Teams {

		var row []string

		row = append(row, fmt.Sprintf("%d", tr.Rank))
		row = append(row, tr.Name)
		row = append(row, fmt.Sprintf("%05.2f%%", tr.ScorePercent))
		row = append(row, fmt.Sprintf("%.3f", tr.Attack))
		row = append(row, fmt.Sprintf("%.3f", tr.Defence))
		row = append(row, fmt.Sprintf("%d", tr.Advisory))

		table.Append(row)
	}

	table.Render()
}
Example #20
0
func servicesListCmd(c *CLI, ctx *cli.Context) {
	api := c.GetAPIClient(ctx)
	instance := c.GetInstance(ctx, nil)
	services, err := api.Services.List(&*instance.URL)
	if err != nil {
		fatal(err.Error())
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Name", "Kind", "Replicas", "Web URL", "State"})
	for i := range services {
		service := services[i]
		var webURL string
		if service.WebURL != nil {
			webURL = *service.WebURL
		}
		table.Append([]string{
			*service.Name,
			*service.Kind,
			strconv.Itoa(*service.Replicas),
			webURL,
			*service.State,
		})
	}
	table.Render()
}
Example #21
0
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	bh, err := client.GetBillingHistory(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain billing history: %s", err)
	}

	fmt.Printf("Billing history for %s:\n", bh.AccountAlias)
	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_RIGHT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{"Date", "Debit", "Credit", "ID", "Description"})

	for _, le := range bh.BillingHistory {
		table.Append([]string{
			le.Date.Time.Format("Jan 2006"),
			fmt.Sprintf("%.2f", le.Debit),
			fmt.Sprintf("%.2f", le.Credit),
			le.InvoiceID, le.Description,
		})
	}
	table.Render()
}
Example #22
0
File: list.go Project: hex2a/lxd
func listContainers(cinfos []shared.ContainerInfo, filters []string, columns []Column) error {
	headers := []string{}
	for _, column := range columns {
		headers = append(headers, column.Name)
	}

	data := [][]string{}
	for _, cinfo := range cinfos {
		if !shouldShow(filters, &cinfo.State) {
			continue
		}
		d := []string{}
		for _, column := range columns {
			d = append(d, column.Data(cinfo))
		}
		data = append(data, d)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoWrapText(false)
	table.SetRowLine(true)
	table.SetHeader(headers)
	sort.Sort(ByName(data))
	table.AppendBulk(data)
	table.Render()

	return nil
}
Example #23
0
File: field.go Project: Rompei/lgb
// DrawTable draws table of the world
func (f *Field) drawTable() {
	firstRow := make([]string, f.SizeX+1)
	firstRow[0] = ""
	for x := 0; x < f.SizeX; x++ {
		index := strconv.FormatInt(int64(x), 10)
		firstRow[x+1] = index
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetRowLine(true)
	table.Append(firstRow)
	for y := 0; y < f.SizeY; y++ {
		col := make([]string, f.SizeX+1)
		col[0] = strconv.FormatInt(int64(y), 10)
		for x := 0; x < f.SizeX; x++ {
			if f.Points[y][x].IsAlive {
				col[x+1] = string([]rune(f.Points[y][x].Str)[0])
			} else {
				col[x+1] = ""
			}
		}
		table.Append(col)
	}
	table.Render()

}
Example #24
0
func volumeList(ctx *cli.Context) {
	docker := getDockerClient(ctx)

	volumes := setup(docker, ctx.GlobalString("docker-root"))

	if ctx.Bool("quiet") {
		var out []string
		for _, vol := range volumes.s {
			id := vol.ID
			out = append(out, id)
		}
		fmt.Fprintln(os.Stdout, strings.Join(out, "\n"))
		return
	}
	var items [][]string
	for _, vol := range volumes.s {
		id := vol.ID
		if len(id) > 12 {
			id = id[:12]
		}
		out := []string{id, strings.Join(vol.Names, ", "), vol.HostPath}
		items = append(items, out)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"ID", "Names", "Path"})
	table.SetBorder(false)
	table.AppendBulk(items)
	table.Render()
}
Example #25
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	u, err := client.GetUserDetails(*user)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Name", "Email", "Password", "Admin?", "Updatable?", "Last Logged In", "Internal Password Disabled?", "Realm", "Groups"})
		table.SetAutoWrapText(false)
		table.Append([]string{
			u.Name,
			u.Email,
			"<hidden>",
			strconv.FormatBool(u.Admin),
			strconv.FormatBool(u.ProfileUpdatable),
			u.LastLoggedIn,
			strconv.FormatBool(u.InternalPasswordDisabled),
			u.Realm,
			strings.Join(u.Groups, "\n"),
		})
		table.Render()
		os.Exit(0)
	}
}
Example #26
0
File: list.go Project: grrtrr/clcv1
func main() {
	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	accts, err := client.GetAccounts()
	if err != nil {
		exit.Fatalf("Failed to obtain account list: %s", err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{"Account", "Parent", "Location", "Business Name"})
	for _, a := range accts {
		var acct = a.AccountAlias

		if !a.IsActive {
			acct += " (INACTIVE)"
		}
		table.Append([]string{acct, a.ParentAlias, a.Location, a.BusinessName})
	}
	table.Render()
}
Example #27
0
func showImages(images []shared.ImageInfo) error {
	data := [][]string{}
	for _, image := range images {
		shortest := shortestAlias(image.Aliases)
		if len(image.Aliases) > 1 {
			shortest = fmt.Sprintf("%s (%d more)", shortest, len(image.Aliases)-1)
		}
		fp := image.Fingerprint[0:12]
		public := "no"
		description := findDescription(image.Properties)
		if image.Public == 1 {
			public = "yes"
		}
		const layout = "Jan 2, 2006 at 3:04pm (MST)"
		uploaded := time.Unix(image.UploadDate, 0).Format(layout)
		arch, _ := shared.ArchitectureName(image.Architecture)
		data = append(data, []string{shortest, fp, public, description, arch, uploaded})
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"ALIAS", "FINGERPRINT", "PUBLIC", "DESCRIPTION", "ARCH", "UPLOAD DATE"})

	for _, v := range data {
		table.Append(v)
	}
	table.Render()

	return nil
}
Example #28
0
func main() {
	kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version("1.0").Author("John E. Vincent")
	kingpin.CommandLine.Help = "List all users in Artifactory"
	kingpin.Parse()

	client := artifactory.NewClientFromEnv()
	data, err := client.GetUsers()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		if *format == "table" {
			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{"Name", "Uri"})
			table.SetAutoWrapText(false)
			for _, u := range data {
				table.Append([]string{u.Name, u.Uri})
			}
			table.Render()
		} else if *format == "list" {
			for _, u := range data {
				fmt.Printf("%s\n", u.Name)
			}
		} else if *format == "csv" {
			for _, u := range data {
				fmt.Printf("%s%s%s\n", u.Name, *sep, u.Uri)
			}
		}
		os.Exit(0)
	}
}
Example #29
0
File: util.go Project: tkuchiki/alp
func Output(ps Profiles, c Config) {
	if c.Tsv {
		if !c.NoHeaders {
			fmt.Printf("Count\tMin\tMax\tSum\tAvg\tP1\tP50\tP99\tStddev\tMin(Body)\tMax(Body)\tSum(Body)\tAvg(Body)\tMethod\tUri")
			fmt.Println("")
		}

		for _, p := range ps {
			fmt.Printf("%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v",
				p.Cnt, Round(p.Min), Round(p.Max), Round(p.Sum), Round(p.Avg),
				Round(p.P1), Round(p.P50), Round(p.P99), Round(p.Stddev),
				Round(p.MinBody), Round(p.MaxBody), Round(p.SumBody), Round(p.AvgBody),
				p.Method, p.Uri)
			fmt.Println("")
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Count", "Min", "Max", "Sum", "Avg",
			"P1", "P50", "P99", "Stddev",
			"Min(Body)", "Max(Body)", "Sum(Body)", "Avg(Body)",
			"Method", "Uri"})
		for _, p := range ps {
			data := []string{
				fmt.Sprint(p.Cnt), Round(p.Min), Round(p.Max), Round(p.Sum), Round(p.Avg),
				Round(p.P1), Round(p.P50), Round(p.P99), Round(p.Stddev),
				Round(p.MinBody), Round(p.MaxBody), Round(p.SumBody), Round(p.AvgBody),
				p.Method, p.Uri}
			table.Append(data)
		}
		table.Render()
	}
}
Example #30
0
func List() error {
	c := config.ScalingoClient()
	apps, err := c.AppsList()
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	if len(apps) == 0 {
		fmt.Println(io.Indent("\nYou haven't created any app yet, create your first application using:\n→ scalingo create <app_name>\n", 2))
		return nil
	}

	t := tablewriter.NewWriter(os.Stdout)
	t.SetHeader([]string{"Name", "Role", "Owner"})

	for _, app := range apps {
		if app.Owner.Email == config.AuthenticatedUser.Email {
			t.Append([]string{app.Name, "owner", "-"})
		} else {
			t.Append([]string{app.Name, "collaborator", fmt.Sprintf("%s <%s>", app.Owner.Username, app.Owner.Email)})
		}
	}
	t.Render()

	return nil
}