Beispiel #1
0
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
}
Beispiel #2
0
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)
}
Beispiel #3
0
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()
	}
}
Beispiel #4
0
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()
	}

}
Beispiel #5
0
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()
}
Beispiel #6
0
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)
}
Beispiel #7
0
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()
}
Beispiel #8
0
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()
}
Beispiel #9
0
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()
}
Beispiel #10
0
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
}
// 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
}
Beispiel #12
0
// 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()
}
Beispiel #13
0
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()
}
Beispiel #14
0
//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()
}
Beispiel #15
0
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()
	}
}
Beispiel #16
0
func (lc *ListCommand) listVariants() error {
	var variants []model.BuildVariant
	if lc.Project != "" {
		ac, _, err := getAPIClient(lc.GlobalOpts)
		if err != nil {
			return err
		}
		notifyUserUpdate(ac)
		variants, err = ac.ListVariants(lc.Project)
		if err != nil {
			return err
		}
	} else if lc.File != "" {
		project, err := loadLocalConfig(lc.File)
		if err != nil {
			return err
		}
		variants = project.BuildVariants
	} else {
		return noProjectError
	}
	fmt.Println(len(variants), "variants:")
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 0, '\t', 0)
	for _, t := range variants {
		line := fmt.Sprintf("\t%v\t", t.Name)
		fmt.Fprintln(w, line)
	}
	w.Flush()
	return nil
}
Beispiel #17
0
func printOther(w *tabwriter.Writer, comps map[string]*Component) {
	var keys sort.StringSlice

	for refdes := range comps {
		keys = append(keys, refdes)
	}

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

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

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

		for _, refdes := range keys {
			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()
	}
}
Beispiel #18
0
func plLsCmd(plCmd *cli.Cmd) {

	plCmd.Command("ls", "list pipelines", func(plLsCmd *cli.Cmd) {

		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 0, 8, 1, '\t', 0)

		plLsCmd.Action = func() {

			fmt.Fprintln(w, "NAME\tDESCRIPTION")

			pipelines, err := devOpSpecSdk.ListPipelines()
			if nil != err {
				fmt.Fprintln(os.Stderr, err)
				cli.Exit(1)
			}

			for _, devOp := range pipelines {

				fmt.Fprintf(w, "%v\t%v", devOp.Name, devOp.Description)
				fmt.Fprintln(w)

			}

			w.Flush()
		}

	})

}
Beispiel #19
0
func (c *AddonsGetCmd) printAddons(addons map[string]*kutil.ClusterAddon) 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 addons {
		b.WriteByte(tabwriter.Escape)
		b.WriteString(n.Name)
		b.WriteByte(tabwriter.Escape)
		b.WriteByte('\t')
		b.WriteByte(tabwriter.Escape)
		b.WriteString(n.Path)
		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()
}
Beispiel #20
0
func PrintSolutionScoring(solution Solution) {
	teams := splitIntoTeams(solution.players)
	totalScore := Score(0)
	writer := new(tabwriter.Writer)
	writer.Init(os.Stdout, 0, 0, 1, ' ', 0)
	for _, criterion := range criteriaToScore {
		rawScore, normalizedScore, weightedScore, rawValues := criterion.analyze(teams)
		totalScore += weightedScore
		fmt.Fprintf(
			writer,
			"%s.\tScore: %.02f\t(= normalized score %.02f * weight %d)\t(raw score %0.2f, worst case %.02f)\tRaw Values: %.02f\n",
			criterion.name, weightedScore, normalizedScore, criterion.weight,
			rawScore, criterion.worstCase, rawValues)
	}
	fmt.Println("Total score: ", totalScore)
	writer.Flush()

	// Print the missing baggages
	for _, team := range teams {
		for _, player := range team.players {
			for _, baggage := range player.baggages {
				_, err := FindPlayer(team.players, baggage)
				if err != nil {
					// Player desired a baggage, but they're not on the team
					fmt.Printf("%v and %v were unfulfilled baggage\n", player, baggage)
				}
			}
		}
	}
}
func instanceListAppVersions(args []string, service *update.Service, out *tabwriter.Writer) int {
	call := service.Appversion.List()

	if instanceFlags.groupId.Get() != nil {
		call.GroupId(instanceFlags.groupId.String())
	}
	if instanceFlags.appId.Get() != nil {
		call.AppId(instanceFlags.appId.String())
	}
	if instanceFlags.start != 0 {
		call.DateStart(instanceFlags.start)
	}

	if instanceFlags.end != 0 {
		call.DateEnd(instanceFlags.end)
	}

	list, err := call.Do()

	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintln(out, "AppID\tGroupID\tVersion\tClients")
	for _, cl := range list.Items {
		fmt.Fprintf(out, "%s\t%s\t%s\t%d\n", cl.AppId, cl.GroupId, cl.Version, cl.Count)
	}
	out.Flush()
	return OK
}
Beispiel #22
0
func main() {
	fmt.Printf("== Bytes used into a time without nanosecs. [4:9]\n\n")

	last0 := time.Date(2015, 1, 2, 0, 0, 0, 0, time.UTC)
	last1 := time.Date(2015, 1, 2, 10, 11, 12, 0, time.UTC)

	last2 := time.Date(2061, 12, 30, 0, 0, 0, 0, time.UTC)
	last3 := time.Date(2061, 12, 30, 10, 11, 12, 0, time.UTC)

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

	for i, t := range []time.Time{last0, last1, last2, last3} {
		bin, err := t.MarshalBinary()
		if err != nil {
			fmt.Println("ERR: %s\n", err)
			continue
		}
		if i == 2 {
			fmt.Println()
		}

		fmt.Fprintf(w, " %s\t::\t%v\n", t, bin)
		//fmt.Println(bin[4:9])
		w.Flush()
	}
}
Beispiel #23
0
func (a analytics) Print() {
	since := time.Since(a.lastAPIReset)
	callsPerSec := float64(a.apiCount) / since.Seconds()
	glog.Infof("Made %d API calls since the last Reset %f calls/sec", a.apiCount, callsPerSec)

	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)
	fmt.Fprintf(w, "RemoveLabels\t%d\t\n", a.RemoveLabels)
	fmt.Fprintf(w, "ListCollaborators\t%d\t\n", a.ListCollaborators)
	fmt.Fprintf(w, "ListIssues\t%d\t\n", a.ListIssues)
	fmt.Fprintf(w, "ListIssueEvents\t%d\t\n", a.ListIssueEvents)
	fmt.Fprintf(w, "ListCommits\t%d\t\n", a.ListCommits)
	fmt.Fprintf(w, "GetCommit\t%d\t\n", a.GetCommit)
	fmt.Fprintf(w, "GetCombinedStatus\t%d\t\n", a.GetCombinedStatus)
	fmt.Fprintf(w, "GetPR\t%d\t\n", a.GetPR)
	fmt.Fprintf(w, "AssignPR\t%d\t\n", a.AssignPR)
	fmt.Fprintf(w, "ClosePR\t%d\t\n", a.ClosePR)
	fmt.Fprintf(w, "OpenPR\t%d\t\n", a.OpenPR)
	fmt.Fprintf(w, "GetContents\t%d\t\n", a.GetContents)
	fmt.Fprintf(w, "CreateComment\t%d\t\n", a.CreateComment)
	fmt.Fprintf(w, "Merge\t%d\t\n", a.Merge)
	w.Flush()
	glog.V(2).Infof("\n%v", buf)
}
Beispiel #24
0
func help() {
	w := new(tabwriter.Writer)
	w.Init(os.Stderr, 4, 0, 2, ' ', 0)
	av0 := path.Base(os.Args[0])

	fmt.Fprintf(w, "Administrative utility for Tao Domain.\n")
	fmt.Fprintf(w, "Usage:\n")
	fmt.Fprintf(w, "  %s newsoft [options] <dir>\t Create a soft tao key set\n", av0)
	fmt.Fprintf(w, "  %s init [options]\t Initialize a new domain\n", av0)
	fmt.Fprintf(w, "  %s policy [options]\t Manage authorization policies\n", av0)
	fmt.Fprintf(w, "  %s user [options]\t Create user keys\n", av0)
	fmt.Fprintf(w, "  %s principal [options]\t Display principal names/hashes\n", av0)
	fmt.Fprintf(w, "\n")

	categories := []options.Category{
		{"all", "Basic options for most commands"},
		{"newsoft", "Options for 'newsoft' command"},
		{"init", "Options for 'init' command"},
		{"policy", "Options for 'policy' command"},
		{"user", "Options for 'user' command"},
		{"principal", "Options for 'principal' command"},
		{"logging", "Options to control log output"},
	}
	options.ShowRelevant(w, categories...)

	w.Flush()
}
Beispiel #25
0
func (m *Manager) update(cmd string) {
	args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ")
	if len(args) < 2 {
		fmt.Println("not enough arguments to 'update' command")
		return
	}

	if !m.isClusterSet() {
		return
	}

	var err error
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 1, '\t', 0)
	fmt.Fprintf(w, "NODE\tSTATUS\n")

	nodes := cluster.ListNodes(m.Cluster, false)
	for node, address := range nodes {
		status := "done"
		err = network.SendUpdateCommand(address, args[1], m.Cluster)
		if err != nil {
			fmt.Println("Error sending update command to node ", node)
			status = "error"
		}

		fmt.Fprintf(w, "%s\t%s\n",
			node,
			status,
		)
	}

	w.Flush()
}
Beispiel #26
0
func outputPluginResults(w io.Writer, byt []byte) error {
	var results []struct {
		ID            uint64
		Name          string
		Description   sql.NullString
		Path          string
		DownloadCount uint64
		Similarity    float64
	}
	if err := json.Unmarshal(byt, &results); err != nil {
		return err
	}
	writer := tabwriter.Writer{}
	writer.Init(w, 0, 8, 1, '\t', 0)
	_, err := writer.Write([]byte("NAME\tDESCRIPTION\tDOWNLOADS\n"))
	if err != nil {
		return err
	}
	for _, result := range results {
		d := result.Description
		if len(d.String) >= 30 {
			d.String = d.String[:27] + "..."
		}
		_, err = writer.Write([]byte(fmt.Sprintf("%s\t%s\t%d\n",
			result.Name, d.String, result.DownloadCount)))
		if err != nil {
			return err
		}
	}
	return writer.Flush()
}
Beispiel #27
0
func (c *Commands) help(t *Term, ctx callContext, args string) error {
	if args != "" {
		for _, cmd := range c.cmds {
			for _, alias := range cmd.aliases {
				if alias == args {
					fmt.Println(cmd.helpMsg)
					return nil
				}
			}
		}
		return noCmdError
	}

	fmt.Println("The following commands are available:")
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 0, '-', 0)
	for _, cmd := range c.cmds {
		h := cmd.helpMsg
		if idx := strings.Index(h, "\n"); idx >= 0 {
			h = h[:idx]
		}
		if len(cmd.aliases) > 1 {
			fmt.Fprintf(w, "    %s (alias: %s) \t %s\n", cmd.aliases[0], strings.Join(cmd.aliases[1:], " | "), h)
		} else {
			fmt.Fprintf(w, "    %s \t %s\n", cmd.aliases[0], h)
		}
	}
	if err := w.Flush(); err != nil {
		return err
	}
	fmt.Println("Type help followed by a command for full documentation.")
	return nil
}
Beispiel #28
0
func (lp *ListProjectsCommand) Execute(args []string) error {
	ac, _, err := getAPIClient(lp.GlobalOpts)
	if err != nil {
		return err
	}
	notifyUserUpdate(ac)

	projs, err := ac.ListProjects()
	if err != nil {
		return err
	}
	ids := make([]string, 0, len(projs))
	names := make(map[string]string)
	for _, proj := range projs {
		// Only list projects that are enabled
		if proj.Enabled {
			ids = append(ids, proj.Identifier)
			names[proj.Identifier] = proj.DisplayName
		}
	}
	sort.Strings(ids)
	fmt.Println(len(ids), "projects:")
	w := new(tabwriter.Writer)
	// Format in tab-separated columns with a tab stop of 8.
	w.Init(os.Stdout, 0, 8, 0, '\t', 0)
	for _, id := range ids {
		line := fmt.Sprintf("\t%v\t", id)
		if len(names[id]) > 0 && names[id] != id {
			line = line + fmt.Sprintf("(%v)", names[id])
		}
		fmt.Fprintln(w, line)
	}
	w.Flush()
	return nil
}
Beispiel #29
0
// resultTypeHelp generates and returns formatted help for the provided result
// type.
func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string {
	// Generate the JSON example for the result type.
	results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey)

	// When this is a primitive type, add the associated JSON type and
	// result description into the final string, format it accordingly,
	// and return it.
	if !isComplex {
		return fmt.Sprintf("%s (%s) %s", results[0],
			reflectTypeToJSONType(xT, rt), xT(fieldDescKey))
	}

	// At this point, this is a complex type that already has the JSON types
	// and descriptions in the results.  Thus, use a tab writer to nicely
	// align the help text.
	var formatted bytes.Buffer
	w := new(tabwriter.Writer)
	w.Init(&formatted, 0, 4, 1, ' ', 0)
	for i, text := range results {
		if i == len(results)-1 {
			fmt.Fprintf(w, text)
		} else {
			fmt.Fprintln(w, text)
		}
	}
	w.Flush()
	return formatted.String()
}
Beispiel #30
0
func (lt *ListTasksCommand) Execute(args []string) error {
	ac, _, err := getAPIClient(lt.GlobalOpts)
	if err != nil {
		return err
	}
	notifyUserUpdate(ac)
	var tasks []model.ProjectTask
	if lt.Project != "" {
		tasks, err = ac.ListTasks(lt.Project)
		if err != nil {
			return err
		}
	} else if lt.File != "" {
		project, err := loadLocalConfig(lt.File)
		if err != nil {
			return err
		}
		tasks = project.Tasks
	} else {
		return fmt.Errorf("must specify a project with -p/--project or a path to a config file with -f/--file")
	}
	fmt.Println(len(tasks), "tasks:")
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 0, '\t', 0)
	for _, t := range tasks {
		line := fmt.Sprintf("\t%v\t", t.Name)
		fmt.Fprintln(w, line)
	}
	w.Flush()
	return nil

}