<commit_before>package command

import (
	"fmt"

	"code.google.com/p/go-uuid/uuid"
	"github.com/codegangsta/cli"
)

func NewResultCommand() cli.Command {
	cmd := cli.Command{
		Name: "result",
		Usage: "get task results",
		Action: execResultCommand,
		Flags: []cli.Flag{
			cli.StringFlag{
				Name: "minion",
				Usage: "get task result for given minion only",
			},
		},
	}

	return cmd
}

// Executes the "result" command
func execResultCommand(c *cli.Context) {
	if len(c.Args()) == 0 {
		displayError(errMissingTask, 64)
	}

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

	client := newEtcdMinionClientFromFlags(c)

	// If --minion flag was specified parse the
	// minion uuid and get the task result only
	// from the specified minion, otherwise find
	// all minions which contain the given
	// task and get their results
	var minionWithTask []uuid.UUID

	mFlag := c.String("minion")
	if mFlag == "" {
		// No minion was specified, get all minions
		// with the given task uuid
		m, err := client.MinionWithTaskResult(taskId)
		if err != nil {
			displayError(err, 1)
		}
		minionWithTask = m
	} else {
		// Minion was specified, get task result
		// from the given minion only
		minion := uuid.Parse(mFlag)
		if minion == nil {
			displayError(errInvalidUUID, 64)
		}
		minionWithTask = append(minionWithTask, minion)
	}

	for _, minion := range minionWithTask {
		task, err := client.MinionTaskResult(minion, taskId)
		if err != nil {
			displayError(err, 1)
		}

		fmt.Printf("Minion: %s\n", minion)
		fmt.Printf("Result: %s\n\n", task.Result)
	}
}<commit_msg>gructl: Display task results using a table<commit_after>package command

import (
	"fmt"

	"code.google.com/p/go-uuid/uuid"
	"github.com/codegangsta/cli"
	"github.com/gosuri/uitable"
)

func NewResultCommand() cli.Command {
	cmd := cli.Command{
		Name: "result",
		Usage: "get task results",
		Action: execResultCommand,
		Flags: []cli.Flag{
			cli.StringFlag{
				Name: "minion",
				Usage: "get task result for given minion only",
			},
		},
	}

	return cmd
}

// Executes the "result" command
func execResultCommand(c *cli.Context) {
	if len(c.Args()) == 0 {
		displayError(errMissingTask, 64)
	}

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

	client := newEtcdMinionClientFromFlags(c)

	// If --minion flag was specified parse the
	// minion uuid and get the task result only
	// from the specified minion, otherwise find
	// all minions which contain the given
	// task and get their results
	var minionWithTask []uuid.UUID

	mFlag := c.String("minion")
	if mFlag == "" {
		// No minion was specified, get all minions
		// with the given task uuid
		m, err := client.MinionWithTaskResult(taskId)
		if err != nil {
			displayError(err, 1)
		}
		minionWithTask = m
	} else {
		// Minion was specified, get task result
		// from the given minion only
		minion := uuid.Parse(mFlag)
		if minion == nil {
			displayError(errInvalidUUID, 64)
		}
		minionWithTask = append(minionWithTask, minion)
	}

	if len(minionWithTask) == 0 {
		displayError(errNoMinionFound, 1)
	}

	// Create table for the task results
	table := uitable.New()
	table.MaxColWidth = 60
	table.AddRow("MINION", "RESULT")

	for _, minion := range minionWithTask {
		task, err := client.MinionTaskResult(minion, taskId)
		if err != nil {
			displayError(err, 1)
		}

		table.AddRow(minion, task.Result)
	}

	fmt.Println(table)
}
{'fraction_non_alphanumeric': 0.1285878300803674, 'fraction_numerical': 0.006888633754305396, 'mean_word_length': 3.4565217391304346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '499932', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1244, 'n_words': 339}