// SpartaCommand issues a go run command that encapsulates resolving
// global env vars that can be translated into Sparta command line options
8148
func SpartaCommand(commandParts ...string) error {
	noopValue := ""
	parsedBool, parsedBoolErr := strconv.ParseBool(os.Getenv("NOOP"))
	if parsedBoolErr == nil && parsedBool {
		noopValue = "--noop"
	}
	curDir, curDirErr := os.Getwd()
	if curDirErr != nil {
		return errors.New("Failed to get current directory. Error: " + curDirErr.Error())
	}
	setenvErr := os.Setenv(mg.VerboseEnv, "1")
	if setenvErr != nil {
		return setenvErr
	}
	commandArgs := []string{
		"run",
		curDir,
	}
	commandArgs = append(commandArgs, commandParts...)
	if noopValue != "" {
		commandArgs = append(commandArgs, "--noop")
	}
	return sh.Run("go",
		commandArgs...)
}
368067
func runCommand(name string, args ...string) (*exec.Cmd, error) {
	cmd := exec.Command(name, args...)
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return cmd, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return cmd, err
	}

	if err := cmd.Start(); err != nil {
		return cmd, err
	}

	go io.Copy(os.Stdout, stdout)
	go io.Copy(os.Stderr, stderr)

	return cmd, nil
}
1133932
func (v *VTY) Commands(cmds []string) error {
	for _, cmd := range cmds {
		if _, err := v.Command(cmd); err != nil {
			return err
		}
	}
	return nil
}
4640
func runCommand(ctx context.Context, command []string) error {
	cmd := exec.Command(command[0], command[1:]...)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	return cmd.Run()
}
334358
func Command(scriptName string, args ...string) (*exec.Cmd, error) {
	// Make sure this is a script name, not a path.
	if strings.Contains(scriptName, "/") {
		return nil, fmt.Errorf("not a script name: %v", scriptName)
	}

	// Get the list of available scripts.
	root, err := gitutil.RepositoryRootAbsolutePath()
	if err != nil {
		return nil, err
	}

	scriptsDirPath := filepath.Join(root, config.LocalConfigDirname, ScriptDirname)

	scriptsDir, err := os.Open(scriptsDirPath)
	if err != nil {
		return nil, err
	}
	defer scriptsDir.Close()

	scripts, err := scriptsDir.Readdirnames(-1)
	if err != nil {
		return nil, err
	}

	// Choose the first available script for the given script name.
	// Return a command for that script based on the file extension and platform.
	currentPlatformId := runners.ParsePlatform(runtime.GOOS)

	for _, script := range scripts {
		// To understand the loop:
		//   script     = ${base}.${ext}
		//   base       = ${name}_${platform}
		//   (=> script = ${name}_${platform}.${ext})

		// Get the file extension.
		ext := filepath.Ext(script)
		if ext == "" {
			continue
		}

		// Get the file base, i.e. the filename without the file extension.
		base := script[:len(script)-len(ext)]

		// In case the whole base matches, this is a cross-platform script and we are done.
		// Otherwise we have to parse the base further and decide what to do.
		var platformId runners.Platform
		if base == scriptName {
			platformId = currentPlatformId
		} else {
			// Split the base.
			parts := strings.Split(base, "_")

			// Make sure the platform matches the current platform.
			platform := parts[len(parts)-1]
			platformId = runners.ParsePlatform(platform)
			if platformId != currentPlatformId {
				continue
			}

			// Make sure the name matches the requested script name.
			name := base[:len(base)-len(platform)-1]
			if name != scriptName {
				continue
			}
		}

		// Get the runner for the given file extension.
		// ext contains the dot, which we need to drop.
		runner := runners.GetRunner(ext[1:], platformId)
		if runner == nil {
			continue
		}
		cmd := runner.NewCommand(filepath.Join(scriptsDirPath, script))
		cmd.Args = append(cmd.Args, args...)
		cmd.Dir = root
		return cmd, nil
	}

	return nil, &ErrNotFound{scriptName}
}
972675
func (cli *HyperClient) Cmd(args ...string) error {
	if len(args) > 1 {
		method, exists := cli.getMethod(args[:2]...)
		if exists {
			return method(args[2:]...)
		}
	}
	if len(args) > 0 {
		method, exists := cli.getMethod(args[0])
		if !exists {
			fmt.Printf("%s: '%s' is not a %s command. See '%s --help'.\n", os.Args[0], args[0], os.Args[0], os.Args[0])
			os.Exit(1)
		}
		return method(args[1:]...)
	}
	return cli.HyperCmdHelp()
}
323886
func (c *CLI) helpCommands(prefix string) map[string]CommandFactory {
	// If our prefix isn't empty, make sure it ends in ' '
	if prefix != "" && prefix[len(prefix)-1] != ' ' {
		prefix += " "
	}

	// Get all the subkeys of this command
	var keys []string
	c.commandTree.WalkPrefix(prefix, func(k string, raw interface{}) bool {
		// Ignore any sub-sub keys, i.e. "foo bar baz" when we want "foo bar"
		if !strings.Contains(k[len(prefix):], " ") {
			keys = append(keys, k)
		}

		return false
	})

	// For each of the keys return that in the map
	result := make(map[string]CommandFactory, len(keys))
	for _, k := range keys {
		raw, ok := c.commandTree.Get(k)
		if !ok {
			// We just got it via WalkPrefix above, so we just panic
			panic("not found: " + k)
		}

		// If this is a hidden command, don't show it
		if _, ok := c.commandHidden[k]; ok {
			continue
		}

		result[k] = raw.(CommandFactory)
	}

	return result
}
496166
func RunCommand(factory app.ProjectFactory) cli.Command {
	return cli.Command{
		Name:   "run",
		Usage:  "Run a one-off command",
		Action: app.WithProject(factory, app.ProjectRun),
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "d",
				Usage: "Detached mode: Run container in the background, print new container name.",
			},
		},
	}
}
730344
func (m *DirectoryMigratorService) RunCommand(c *cli.Context) {
	fmt.Println("Running migrations...")

	db, _ := m.Connections.Make()
	db.LogMode(true)

	m.Migrations.Run(m.Directory.GetModels())

	fmt.Println("✔︎ Done!")
}
1009367
func Command(args ...string) *exec.Cmd {
	return &exec.Cmd{
		Path: Self(),
		Args: args,
	}
}
1176650
func (_m *CommandRegistrar) Command(name string, help string, onCommand common.CLICommand) *kingpin.CmdClause {
	ret := _m.Called(name, help, onCommand)

	var r0 *kingpin.CmdClause
	if rf, ok := ret.Get(0).(func(string, string, common.CLICommand) *kingpin.CmdClause); ok {
		r0 = rf(name, help, onCommand)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*kingpin.CmdClause)
		}
	}

	return r0
}
619137
func (t *Transaction) Command(name string, args redis.Args, handler ReplyHandler) {
	t.actions = append(t.actions, &Action{
		kind:    commandAction,
		name:    name,
		args:    args,
		handler: handler,
	})
}
1002583
func RunSSHCommand(cmd, user, host string, signer ssh.Signer) (string, string, int, error) {
	return runSSHCommand(realTimeoutDialer, cmd, user, host, signer, true)
}
791423
func (m *MockCommandRunner) RunCommands(arg0 exec.RunParams) (*exec.ExecResponse, error) {
	ret := m.ctrl.Call(m, "RunCommands", arg0)
	ret0, _ := ret[0].(*exec.ExecResponse)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
522633
func PuppetAIOCmd(command string, def string) string {
	return puppet.AIOCmd(command, def)
}
95300
func (tio *Timeout) RunCommand() (<-chan *ExitStatus, error) {
	if err := tio.start(); err != nil {
		return nil, err
	}

	exitChan := make(chan *ExitStatus)
	go func() {
		exitChan <- tio.wait(context.Background())
	}()
	return exitChan, nil
}
1244572
func (tc *TeleportClient) runCommand(
	ctx context.Context, siteName string, nodeAddresses []string, proxyClient *ProxyClient, command []string) error {

	resultsC := make(chan error, len(nodeAddresses))
	for _, address := range nodeAddresses {
		go func(address string) {
			var (
				err         error
				nodeSession *NodeSession
			)
			defer func() {
				resultsC <- err
			}()
			var nodeClient *NodeClient
			nodeClient, err = proxyClient.ConnectToNode(ctx, address+"@"+tc.Namespace+"@"+siteName, tc.Config.HostLogin, false)
			if err != nil {
				fmt.Fprintln(tc.Stderr, err)
				return
			}
			defer nodeClient.Close()

			// run the command on one node:
			if len(nodeAddresses) > 1 {
				fmt.Printf("Running command on %v:\n", address)
			}
			nodeSession, err = newSession(nodeClient, nil, tc.Config.Env, tc.Stdin, tc.Stdout, tc.Stderr)
			if err != nil {
				log.Error(err)
				return
			}
			defer nodeSession.Close()
			if err = nodeSession.runCommand(ctx, command, tc.OnShellCreated, tc.Config.Interactive); err != nil {
				originErr := trace.Unwrap(err)
				exitErr, ok := originErr.(*ssh.ExitError)
				if ok {
					tc.ExitStatus = exitErr.ExitStatus()
				} else {
					// if an error occurs, but no exit status is passed back, GoSSH returns
					// a generic error like this. in this case the error message is printed
					// to stderr by the remote process so we have to quietly return 1:
					if strings.Contains(originErr.Error(), "exited without exit status") {
						tc.ExitStatus = 1
					}
				}
			}
		}(address)
	}
	var lastError error
	for range nodeAddresses {
		if err := <-resultsC; err != nil {
			lastError = err
		}
	}
	return trace.Wrap(lastError)
}