<commit_before>package commands

import (
	"github.com/ghodss/yaml"
	"github.com/jawher/mow.cli"
	"github.com/mesos/mesos-go"
	"github.com/vektorlab/mesos-cli/config"
	"github.com/vektorlab/mesos-cli/runner"
	"io/ioutil"
	"os"
)

type Run struct{}

func (_ Run) Name() string { return "run" }
func (_ Run) Desc() string { return "Run tasks on Mesos" }

func (_ Run) Init(profile config.ProfileFn) func(*cli.Cmd) {
	return func(cmd *cli.Cmd) {
		cmd.Spec = "[OPTIONS] [FILE]"

		var (
			file     = cmd.StringArg("FILE", "Mesosfile", "File containing Mesos TaskInfos, - for stdin")
			hostname = cmd.StringOpt("m master", "", "Mesos Master")
			restart  = cmd.BoolOpt("restart", false, "Restart containers on failure")
			sync     = cmd.BoolOpt("s sync", false, "Run containers synchronously")
		)

		cmd.Action = func() {
			profile().With(
				config.Master(*hostname),
				config.Restart(*restart),
				config.Sync(*sync),
			)

			tasks := []*mesos.TaskInfo{}

			if *file == "-" {
				raw, err := ioutil.ReadAll(os.Stdin)
				failOnErr(err)
				failOnErr(yaml.Unmarshal(raw, &tasks))
			} else {
				raw, err := ioutil.ReadFile(*file)
				failOnErr(err)
				failOnErr(yaml.Unmarshal(raw, &tasks))
			}
			failOnErr(runner.Run(profile(), tasks))
		}
	}
}<commit_msg>add default resources and port mappings to run input<commit_after>package commands

import (
	"github.com/ghodss/yaml"
	"github.com/jawher/mow.cli"
	"github.com/mesos/mesos-go"
	"github.com/vektorlab/mesos-cli/commands/options"
	"github.com/vektorlab/mesos-cli/config"
	"github.com/vektorlab/mesos-cli/runner"
	"io/ioutil"
	"os"
)

type Run struct{}

func (_ Run) Name() string { return "run" }
func (_ Run) Desc() string { return "Run tasks on Mesos" }

func (_ Run) Init(profile config.ProfileFn) func(*cli.Cmd) {
	return func(cmd *cli.Cmd) {
		cmd.Spec = "[OPTIONS] [FILE]"

		var (
			file     = cmd.StringArg("FILE", "Mesosfile", "File containing Mesos TaskInfos, - for stdin")
			hostname = cmd.StringOpt("m master", "", "Mesos Master")
			restart  = cmd.BoolOpt("restart", false, "Restart containers on failure")
			sync     = cmd.BoolOpt("s sync", false, "Run containers synchronously")
		)

		cmd.Action = func() {
			profile().With(
				config.Master(*hostname),
				config.Restart(*restart),
				config.Sync(*sync),
			)

			tasks := []*mesos.TaskInfo{}

			if *file == "-" {
				raw, err := ioutil.ReadAll(os.Stdin)
				failOnErr(err)
				failOnErr(yaml.Unmarshal(raw, &tasks))
			} else {
				raw, err := ioutil.ReadFile(*file)
				failOnErr(err)
				failOnErr(yaml.Unmarshal(raw, &tasks))
			}

			for _, task := range tasks {
				options.Apply(
					task,
					options.WithDefaultResources(),
					options.WithPorts(),
				)
			}

			failOnErr(runner.Run(profile(), tasks))
		}
	}
}
{'fraction_non_alphanumeric': 0.16522053506869125, 'fraction_numerical': 0.0, 'mean_word_length': 3.491883116883117, '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': '3658312', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1021, 'n_words': 203}