<commit_before>package command

import (
	"fmt"

	"koding/kites/kloud/kloud"

	"github.com/koding/kite"
	"github.com/mitchellh/cli"
)

type Stop struct {
	id *string
}

func NewStop() cli.CommandFactory {
	return func() (cli.Command, error) {
		f := NewFlag("stop", "Stop a machine")
		f.action = &Stop{
			id: f.String("id", "", "Machine id of to be stopped."),
		}
		return f, nil
	}
}

func (s *Stop) Action(args []string, k *kite.Client) error {
	stopArgs := &KloudArgs{
		MachineId: *s.id,
		Username:  flagUsername,
	}

	resp, err := k.Tell("stop", stopArgs)
	if err != nil {
		return err
	}

	var result kloud.ControlResult
	err = resp.Unmarshal(&result)
	if err != nil {
		return err
	}

	DefaultUi.Info(fmt.Sprintf("%+v", result))

	if flagWatchEvents {
		return watch(k, "stop", *s.id, defaultPollInterval)
	}
	return nil<commit_msg>kloudctl/stop: initial batch support for stop<commit_after>package command

import (
	"fmt"
	"strings"
	"sync"

	"koding/kites/kloud/kloud"

	"github.com/koding/kite"
	"github.com/mitchellh/cli"
)

type Stop struct {
	ids *string
}

func NewStop() cli.CommandFactory {
	return func() (cli.Command, error) {
		f := NewFlag("stop", "Stop a machine")
		f.action = &Stop{
			ids: f.String("ids", "", "Machine id of information being showed."),
		}
		return f, nil
	}
}

func (s *Stop) SingleMachine(id string, k *kite.Client) (string, error) {
	stop := &KloudArgs{
		MachineId: id,
	}

	resp, err := k.Tell("stop", stop)
	if err != nil {
		return "", err
	}

	var result kloud.ControlResult
	err = resp.Unmarshal(&result)
	if err != nil {
		return "", err
	}

	return result.EventId, nil
}

func (s *Stop) Action(args []string, k *kite.Client) error {
	machines := strings.Split(*s.ids, ",")

	var wg sync.WaitGroup
	for _, id := range machines {
		wg.Add(1)

		go func(id string) {
			defer wg.Done()
			result, err := s.SingleMachine(id, k)
			if err != nil {
				DefaultUi.Error(err.Error())
			} else {
				DefaultUi.Info(fmt.Sprintf("%+v", result))
			}
		}(id)
	}

	DefaultUi.Info(fmt.Sprintf("stop called for '%d' machines:\n", len(machines)))

	wg.Wait()

	if len(machines) == 1 {
		if flagWatchEvents {
			return watch(k, "stop", machines[0], defaultPollInterval)
		}
	}

	return nil
{'fraction_non_alphanumeric': 0.16315553563424473, 'fraction_numerical': 0.001344688480502017, 'mean_word_length': 3.5644171779141103, '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': '3827580', 'n_tokens_mistral': 916, 'n_tokens_neox': 845, 'n_words': 213}