示例#1
0
文件: list.go 项目: dnaeon/gru
// Executes the "list" command
func execListCommand(c *cli.Context) error {
	klient := newEtcdMinionClientFromFlags(c)

	cFlag := c.String("with-classifier")
	minions, err := parseClassifierPattern(klient, cFlag)

	// Ignore errors about missing minion directory
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if len(minions) == 0 {
		return nil
	}

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("MINION", "NAME")
	for _, minion := range minions {
		name, err := klient.MinionName(minion)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}

		table.AddRow(minion, name)
	}

	fmt.Println(table)

	return nil
}
示例#2
0
文件: lastseen.go 项目: dnaeon/gru
// Executes the "lastseen" command
func execLastseenCommand(c *cli.Context) error {
	client := newEtcdMinionClientFromFlags(c)

	cFlag := c.String("with-classifier")
	minions, err := parseClassifierPattern(client, cFlag)

	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("MINION", "LASTSEEN")
	for _, minion := range minions {
		lastseen, err := client.MinionLastseen(minion)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}

		table.AddRow(minion, time.Unix(lastseen, 0))
	}

	fmt.Println(table)

	return nil
}
示例#3
0
文件: main.go 项目: whawty/auth
func cmdListFull(s *StoreChan) error {
	lst, err := s.ListFull()
	if err != nil {
		return fmt.Errorf("Error listing user: %s\n", err)
	}

	var keys []string
	for k := range lst {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("NAME", "TYPE", "LAST-CHANGED", "VALID", "SUPPORTED", "FORMAT", "PARAMS")
	for _, k := range keys {
		t := "user"
		if lst[k].IsAdmin {
			t = "admin"
		}
		table.AddRow(k, t, lst[k].LastChanged.String(), lst[k].IsValid, lst[k].IsSupported, lst[k].FormatID, lst[k].FormatParams)
	}
	fmt.Println(table)
	return nil
}
示例#4
0
文件: main.go 项目: whawty/auth
func cmdListSupported(s *StoreChan) error {
	lst, err := s.List()
	if err != nil {
		return fmt.Errorf("Error listing user: %s\n", err)
	}

	var keys []string
	for k := range lst {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	table := uitable.New()
	table.MaxColWidth = 50
	table.AddRow("NAME", "TYPE", "LAST-CHANGED")
	for _, k := range keys {
		t := "user"
		if lst[k].IsAdmin {
			t = "admin"
		}
		table.AddRow(k, t, lst[k].LastChanged.String())
	}
	fmt.Println(table)
	return nil
}
示例#5
0
// Executes the "queue" command
func execQueueCommand(c *cli.Context) {
	if len(c.Args()) == 0 {
		displayError(errMissingMinion, 64)
	}

	minion := uuid.Parse(c.Args()[0])
	if minion == nil {
		displayError(errInvalidUUID, 64)
	}

	client := newEtcdMinionClientFromFlags(c)

	// Ignore errors about missing queue directory
	queue, err := client.MinionTaskQueue(minion)
	if err != nil {
		if eerr, ok := err.(etcdclient.Error); !ok || eerr.Code != etcdclient.ErrorCodeKeyNotFound {
			displayError(err, 1)
		}
	}

	if len(queue) == 0 {
		return
	}

	table := uitable.New()
	table.MaxColWidth = 40
	table.AddRow("TASK", "COMMAND", "STATE", "TIME")
	for _, task := range queue {
		table.AddRow(task.TaskID, task.Command, task.State, time.Unix(task.TimeReceived, 0))
	}

	fmt.Println(table)
}
示例#6
0
文件: queue.go 项目: dnaeon/gru
// Executes the "queue" command
func execQueueCommand(c *cli.Context) error {
	if len(c.Args()) == 0 {
		return cli.NewExitError(errNoMinion.Error(), 64)
	}

	minion := uuid.Parse(c.Args()[0])
	if minion == nil {
		return cli.NewExitError(errInvalidUUID.Error(), 64)
	}

	klient := newEtcdMinionClientFromFlags(c)

	// Ignore errors about missing queue directory
	queue, err := klient.MinionTaskQueue(minion)
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	if len(queue) == 0 {
		return nil
	}

	table := uitable.New()
	table.MaxColWidth = 40
	table.AddRow("TASK", "STATE", "RECEIVED")
	for _, t := range queue {
		table.AddRow(t.ID, t.State, time.Unix(t.TimeReceived, 0))
	}

	fmt.Println(table)

	return nil
}
示例#7
0
文件: info.go 项目: dnaeon/gru
// Executes the "info" command
func execInfoCommand(c *cli.Context) error {
	if len(c.Args()) == 0 {
		return cli.NewExitError(errNoMinion.Error(), 64)
	}

	arg := c.Args()[0]
	minion := uuid.Parse(arg)
	if minion == nil {
		return cli.NewExitError(errInvalidUUID.Error(), 64)
	}

	klient := newEtcdMinionClientFromFlags(c)
	name, err := klient.MinionName(minion)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	lastseen, err := klient.MinionLastseen(minion)
	if err != nil {
		return cli.NewExitError(err.Error(), 1)
	}

	// Ignore errors about missing queue directory
	taskQueue, err := klient.MinionTaskQueue(minion)
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	// Ignore errors about missing log directory
	taskLog, err := klient.MinionTaskLog(minion)
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	// Ignore errors about missing classifier directory
	classifierKeys, err := klient.MinionClassifierKeys(minion)
	if err != nil {
		if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
			return cli.NewExitError(err.Error(), 1)
		}
	}

	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("Minion:", minion)
	table.AddRow("Name:", name)
	table.AddRow("Lastseen:", time.Unix(lastseen, 0))
	table.AddRow("Queue:", len(taskQueue))
	table.AddRow("Log:", len(taskLog))
	table.AddRow("Classifiers:", len(classifierKeys))

	fmt.Println(table)

	return nil
}
示例#8
0
文件: ui.go 项目: hackliff/unlog
func displayMap(writer io.Writer, props map[string]interface{}) {
	table := uitable.New()
	for key, value := range props {
		table.AddRow("", labelUI(key), value)
	}
	fmt.Fprintln(writer, table)
	fmt.Fprintln(writer)
}
示例#9
0
文件: steps.go 项目: nickschuch/steps
// Print out the steps inline.
func Build() string {
	table := uitable.New()
	table.MaxColWidth = 50
	for _, s := range steps {
		table.AddRow(s, s.Complete)
	}
	return table.String()
}
示例#10
0
// printRequirements prints all of the requirements in the yaml file.
func (l *dependencyListCmd) printRequirements(reqs *chartutil.Requirements, out io.Writer) {
	table := uitable.New()
	table.MaxColWidth = 80
	table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS")
	for _, row := range reqs.Dependencies {
		table.AddRow(row.Name, row.Version, row.Repository, l.dependencyStatus(row))
	}
	fmt.Fprintln(out, table)
}
示例#11
0
func repaint(w *uilive.Writer, logCounters []*LogCounter, totalLinesRead int) {
	table := uitable.New()
	table.AddRow("PATTERN", "COUNT", "RATE/s", "RATE/m", "RATE/hr")
	for _, c := range logCounters {
		table.AddRow(c.p.String(), c.c.Value(), c.rsec.String(), c.rmin.String(), c.rhr.String())
	}

	table.AddRow("Total Lines Read:", totalLinesRead, "--", "--", "--")
	fmt.Fprintln(w, table)
	w.Flush()
}
示例#12
0
func (s *searchCmd) formatSearchResults(res []*search.Result) string {
	if len(res) == 0 {
		return "No results found"
	}
	table := uitable.New()
	table.MaxColWidth = 50
	table.AddRow("NAME", "VERSION", "DESCRIPTION")
	for _, r := range res {
		table.AddRow(r.Name, r.Chart.Version, r.Chart.Description)
	}
	return table.String()
}
示例#13
0
文件: util.go 项目: Rompei/vuls
// ToPlainTextSummary format summary for plain text.
func ToPlainTextSummary(r models.ScanResult) string {
	stable := uitable.New()
	stable.MaxColWidth = 84
	stable.Wrap = true

	cves := r.KnownCves
	if !config.Conf.IgnoreUnscoredCves {
		cves = append(cves, r.UnknownCves...)
	}

	for _, d := range cves {
		var scols []string

		switch {
		case config.Conf.Lang == "ja" &&
			0 < d.CveDetail.Jvn.CvssScore():

			summary := d.CveDetail.Jvn.CveTitle()
			scols = []string{
				d.CveDetail.CveID,
				fmt.Sprintf("%-4.1f (%s)",
					d.CveDetail.CvssScore(config.Conf.Lang),
					d.CveDetail.Jvn.CvssSeverity(),
				),
				summary,
			}
		case 0 < d.CveDetail.CvssScore("en"):
			summary := d.CveDetail.Nvd.CveSummary()
			scols = []string{
				d.CveDetail.CveID,
				fmt.Sprintf("%-4.1f (%s)",
					d.CveDetail.CvssScore(config.Conf.Lang),
					d.CveDetail.Nvd.CvssSeverity(),
				),
				summary,
			}
		default:
			scols = []string{
				d.CveDetail.CveID,
				"?",
				d.CveDetail.Nvd.CveSummary(),
			}
		}

		cols := make([]interface{}, len(scols))
		for i := range cols {
			cols[i] = scols[i]
		}
		stable.AddRow(cols...)
	}
	return fmt.Sprintf("%s", stable)
}
示例#14
0
文件: list.go 项目: slack/helm
func formatList(rels []*release.Release) string {
	table := uitable.New()
	table.MaxColWidth = 30
	table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART")
	for _, r := range rels {
		c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version)
		t := timeconv.String(r.Info.LastDeployed)
		s := r.Info.Status.Code.String()
		v := r.Version
		table.AddRow(r.Name, v, t, s, c)
	}
	return table.String()
}
示例#15
0
func formatTabular(metrics ...metric) string {
	table := uitable.New()
	table.MaxColWidth = 50
	table.Wrap = true
	for _, col := range []int{1, 2, 3, 4} {
		table.RightAlign(col)
	}
	table.AddRow("UNIT", "TIMESTAMP", "METRIC", "VALUE")
	for _, m := range metrics {
		table.AddRow(m.Unit, m.Timestamp.Format(time.RFC3339), m.Metric, m.Value)
	}
	return table.String() + "\n"
}
示例#16
0
文件: util.go 项目: ymomoi/vuls
func toOneLineSummary(rs ...models.ScanResult) string {
	table := uitable.New()
	table.MaxColWidth = maxColWidth
	table.Wrap = true
	for _, r := range rs {
		cols := []interface{}{
			r.FormatServerName(),
			r.CveSummary(),
			r.Packages.ToUpdatablePacksSummary(),
		}
		table.AddRow(cols...)
	}
	return fmt.Sprintf("%s\n", table)
}
示例#17
0
func formatHistory(rls []*release.Release) string {
	tbl := uitable.New()
	tbl.MaxColWidth = 30
	tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART")
	for i := len(rls) - 1; i >= 0; i-- {
		r := rls[i]
		c := formatChartname(r.Chart)
		t := timeconv.String(r.Info.LastDeployed)
		s := r.Info.Status.Code.String()
		v := r.Version
		tbl.AddRow(v, t, s, c)
	}
	return tbl.String()
}
示例#18
0
func Example() {
	table := uitable.New()
	table.MaxColWidth = 50

	fmt.Println("==> List")
	table.AddRow("NAME", "BIRTHDAY", "BIO")
	for _, hacker := range hackers {
		table.AddRow(hacker.Name, hacker.Birthday, hacker.Bio)
	}
	fmt.Println(table)

	fmt.Print("\n==> Details\n")
	table = uitable.New()
	table.MaxColWidth = 80
	table.Wrap = true
	for _, hacker := range hackers {
		table.AddRow("Name:", hacker.Name)
		table.AddRow("Birthday:", hacker.Birthday)
		table.AddRow("Bio:", hacker.Bio)
		table.AddRow("") // blank
	}
	fmt.Println(table)
}
示例#19
0
文件: util.go 项目: ymomoi/vuls
func toScanSummary(rs ...models.ScanResult) string {
	table := uitable.New()
	table.MaxColWidth = maxColWidth
	table.Wrap = true
	for _, r := range rs {
		cols := []interface{}{
			r.FormatServerName(),
			fmt.Sprintf("%s%s", r.Family, r.Release),
			fmt.Sprintf("%d CVEs", len(r.ScannedCves)),
			r.Packages.ToUpdatablePacksSummary(),
		}
		table.AddRow(cols...)
	}
	return fmt.Sprintf("%s\n", table)
}
示例#20
0
文件: repo.go 项目: Chronojam/helm
func runRepoList(cmd *cobra.Command, args []string) error {
	f, err := repo.LoadRepositoriesFile(repositoriesFile())
	if err != nil {
		return err
	}
	if len(f.Repositories) == 0 {
		return errors.New("no repositories to show")
	}
	table := uitable.New()
	table.MaxColWidth = 50
	table.AddRow("NAME", "URL")
	for k, v := range f.Repositories {
		table.AddRow(k, v)
	}
	fmt.Println(table)
	return nil
}
示例#21
0
文件: list_plans.go 项目: bac/juju
// formatTabular returns a tabular summary of available plans.
func formatTabular(writer io.Writer, value interface{}) error {
	plans, ok := value.([]plan)
	if !ok {
		return errors.Errorf("expected value of type %T, got %T", plans, value)
	}

	table := uitable.New()
	table.MaxColWidth = 50
	table.Wrap = true

	table.AddRow("Plan", "Price", "Description")
	for _, plan := range plans {
		table.AddRow(plan.URL, plan.Price, plan.Description)
	}
	fmt.Fprint(writer, table)
	return nil
}
示例#22
0
// formatTabular returns a tabular summary of available plans.
func formatTabular(value interface{}) ([]byte, error) {
	plans, ok := value.([]plan)
	if !ok {
		return nil, errors.Errorf("expected value of type %T, got %T", plans, value)
	}

	table := uitable.New()
	table.MaxColWidth = 50
	table.Wrap = true

	table.AddRow("PLAN", "PRICE", "DESCRIPTION")
	for _, plan := range plans {
		table.AddRow(plan.URL, plan.Price, plan.Description)
	}

	return []byte(table.String()), nil
}
示例#23
0
func (a *repoListCmd) run() error {
	f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile())
	if err != nil {
		return err
	}
	if len(f.Repositories) == 0 {
		return errors.New("no repositories to show")
	}
	table := uitable.New()
	table.MaxColWidth = 50
	table.AddRow("NAME", "URL")
	for _, re := range f.Repositories {
		table.AddRow(re.Name, re.URL)
	}
	fmt.Fprintln(a.out, table)
	return nil
}
示例#24
0
文件: repo_list.go 项目: runseb/helm
func (a *repoListCmd) run() error {
	f, err := repo.LoadRepositoriesFile(repositoriesFile())
	if err != nil {
		return err
	}
	if len(f.Repositories) == 0 {
		return errors.New("no repositories to show")
	}
	table := uitable.New()
	table.MaxColWidth = 50
	table.AddRow("NAME", "URL")
	for k, v := range f.Repositories {
		table.AddRow(k, v)
	}
	fmt.Println(table)
	return nil
}
示例#25
0
// ShowStatus cli status
func ShowStatus(entryPoint string) {
	parts := strings.SplitN(entryPoint, "://", 2)
	c, err := net.Dial(parts[0], parts[1])
	if err != nil {
		log.Fatal(err)
	}
	conn := protocol.NewClientConn(c)
	defer conn.Close()
	err = conn.Send(protocol.TYPECLIENT.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	var msgID = []byte("100")
	buf := bytes.NewBuffer(nil)
	buf.Write(msgID)
	buf.Write(protocol.NullChar)
	buf.Write(protocol.STATUS.Bytes())
	err = conn.Send(buf.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	payload, err := conn.Receive()
	if err != nil {
		log.Fatal(err)
	}
	_parts := bytes.SplitN(payload, protocol.NullChar, 2)
	if len(_parts) != 2 {
		err := fmt.Sprint("ParseCommand InvalID %v\n", payload)
		panic(err)
	}
	stats := strings.Split(string(_parts[1]), "\n")
	sort.Strings(stats)
	table := uitable.New()
	table.MaxColWidth = 50

	table.AddRow("FUNCTION", "WORKERS", "JOBS", "PROCESSING")
	for _, stat := range stats {
		if stat == "" {
			continue
		}
		line := strings.Split(stat, ",")
		table.AddRow(line[0], line[1], line[2], line[3])
	}
	fmt.Println(table)
}
示例#26
0
文件: list.go 项目: TechMantra/focus
func displayTasks(trackers map[string][]tracker.Task) {
	table := uitable.New()
	table.AddRow("ID", "TRACKER", "TASK")
	if len(trackers) > 0 {
		var t []string
		for trackr := range trackers {
			t = append(t, trackr)
		}
		sort.Strings(t)
		for _, i := range t {
			for _, task := range trackers[i] {
				table.AddRow(task.ID, i, task.Title)
			}
		}
		fmt.Println(table)
	} else {
		println("No open tasks.")
	}
}
示例#27
0
文件: util.go 项目: Rompei/vuls
func toPlainTextUnknownCve(cveInfo models.CveInfo, osFamily string) string {
	cveID := cveInfo.CveDetail.CveID
	dtable := uitable.New()
	dtable.MaxColWidth = 100
	dtable.Wrap = true
	dtable.AddRow(cveID)
	dtable.AddRow("-------------")
	dtable.AddRow("Score", "?")
	dtable.AddRow("NVD",
		fmt.Sprintf("%s?vulnId=%s", nvdBaseURL, cveID))
	dtable.AddRow("CVE Details",
		fmt.Sprintf("%s/%s", cveDetailsBaseURL, cveID))

	dlinks := distroLinks(cveInfo, osFamily)
	for _, link := range dlinks {
		dtable.AddRow(link.title, link.url)
	}

	return fmt.Sprintf("%s", dtable)
}
示例#28
0
// formatTabular returns a tabular view of available budgets.
func formatTabular(value interface{}) ([]byte, error) {
	b, ok := value.(*wireformat.ListBudgetsResponse)
	if !ok {
		return nil, errors.Errorf("expected value of type %T, got %T", b, value)
	}
	sort.Sort(b.Budgets)

	table := uitable.New()
	table.MaxColWidth = 50
	table.Wrap = true

	table.AddRow("BUDGET", "MONTHLY", "ALLOCATED", "AVAILABLE", "SPENT")
	for _, budgetEntry := range b.Budgets {
		table.AddRow(budgetEntry.Budget, budgetEntry.Limit, budgetEntry.Allocated, budgetEntry.Available, budgetEntry.Consumed)
	}
	table.AddRow("TOTAL", b.Total.Limit, b.Total.Allocated, b.Total.Available, b.Total.Consumed)
	table.AddRow("", "", "", "", "")
	table.AddRow("Credit limit:", b.Credit, "", "", "")
	return []byte(table.String()), nil
}
示例#29
0
// Pretty is a pretty print of a chain
func (c *Chain) Pretty() {
	ks := c.Keys()
	sort.Strings(ks)
	fmt.Fprintf(os.Stdout, "--------------\n")

	table := uitable.New()
	table.MaxColWidth = 50
	table.Separator = "|"

	table.AddRow("Index", "Prefix key", "Available choices")
	for i, x := range ks {
		table.AddRow(
			fmt.Sprintf("\033[0;37m %03d \033[0m", i),
			fmt.Sprintf("\033[0;32m %s \033[0m", x),
			fmt.Sprintf("\033[0;33m %s \033[0m", c.chain[x]))
	}

	fmt.Fprintf(os.Stdout, table.String())
	fmt.Fprintf(os.Stdout, "\n--------------\n")
}
示例#30
0
文件: util.go 项目: ymomoi/vuls
func toPlainTextDetailsLangJa(cveInfo models.CveInfo, osFamily string) string {
	cveDetail := cveInfo.CveDetail
	cveID := cveDetail.CveID
	jvn := cveDetail.Jvn

	dtable := uitable.New()
	dtable.MaxColWidth = maxColWidth
	dtable.Wrap = true
	dtable.AddRow(cveID)
	dtable.AddRow("-------------")
	if score := cveDetail.Jvn.CvssScore(); 0 < score {
		dtable.AddRow("Score",
			fmt.Sprintf("%4.1f (%s)",
				cveDetail.Jvn.CvssScore(),
				jvn.CvssSeverity(),
			))
	} else {
		dtable.AddRow("Score", "?")
	}
	dtable.AddRow("Vector", jvn.CvssVector())
	dtable.AddRow("Title", jvn.CveTitle())
	dtable.AddRow("Description", jvn.CveSummary())
	dtable.AddRow(cveDetail.CweID(), cweURL(cveDetail.CweID()))
	dtable.AddRow(cveDetail.CweID()+"(JVN)", cweJvnURL(cveDetail.CweID()))

	dtable.AddRow("JVN", jvn.Link())
	dtable.AddRow("NVD", fmt.Sprintf("%s?vulnId=%s", nvdBaseURL, cveID))
	dtable.AddRow("MITRE", fmt.Sprintf("%s%s", mitreBaseURL, cveID))
	dtable.AddRow("CVE Details", fmt.Sprintf("%s/%s", cveDetailsBaseURL, cveID))
	dtable.AddRow("CVSS Claculator", cveDetail.CvssV2CalculatorLink("ja"))

	dlinks := distroLinks(cveInfo, osFamily)
	for _, link := range dlinks {
		dtable.AddRow(link.title, link.url)
	}

	dtable = addPackageInfos(dtable, cveInfo.Packages)
	dtable = addCpeNames(dtable, cveInfo.CpeNames)

	return fmt.Sprintf("%s", dtable)
}