// Cmd executes a docker CLI command against this daemon.
// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
973593
func (d *Daemon) Cmd(args ...string) (string, error) {
	result := icmd.RunCmd(d.Command(args...))
	return result.Combined(), result.Error
}
668172
func Cmd(cf *LoggingCmdFactory) *cobra.Command {
	loggingCmd.AddCommand(getLevelCmd(cf))
	loggingCmd.AddCommand(setLevelCmd(cf))
	loggingCmd.AddCommand(revertLevelsCmd(cf))
	loggingCmd.AddCommand(getLogSpecCmd(cf))
	loggingCmd.AddCommand(setLogSpecCmd(cf))

	return loggingCmd
}
1297550
func Command(ctx context.Context, runtime, containerdAddress, path string, cmdArgs ...string) (*exec.Cmd, error) {
	ns, err := namespaces.NamespaceRequired(ctx)
	if err != nil {
		return nil, err
	}
	self, err := os.Executable()
	if err != nil {
		return nil, err
	}
	args := []string{
		"-namespace", ns,
		"-address", containerdAddress,
		"-publish-binary", self,
	}
	args = append(args, cmdArgs...)
	name := BinaryName(runtime)
	if name == "" {
		return nil, fmt.Errorf("invalid runtime name %s, correct runtime name should format like io.containerd.runc.v1", runtime)
	}

	var cmdPath string
	cmdPathI, cmdPathFound := runtimePaths.Load(name)
	if cmdPathFound {
		cmdPath = cmdPathI.(string)
	} else {
		var lerr error
		if cmdPath, lerr = exec.LookPath(name); lerr != nil {
			if eerr, ok := lerr.(*exec.Error); ok {
				if eerr.Err == exec.ErrNotFound {
					// LookPath only finds current directory matches based on
					// the callers current directory but the caller is not
					// likely in the same directory as the containerd
					// executables. Instead match the calling binaries path
					// (containerd) and see if they are side by side. If so
					// execute the shim found there.
					testPath := filepath.Join(filepath.Dir(self), name)
					if _, serr := os.Stat(testPath); serr == nil {
						cmdPath = testPath
					}
					if cmdPath == "" {
						return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name)
					}
				}
			}
		}
		cmdPath, err = filepath.Abs(cmdPath)
		if err != nil {
			return nil, err
		}
		if cmdPathI, cmdPathFound = runtimePaths.LoadOrStore(name, cmdPath); cmdPathFound {
			// We didn't store cmdPath we loaded an already cached value. Use it.
			cmdPath = cmdPathI.(string)
		}
	}

	cmd := exec.Command(cmdPath, args...)
	cmd.Dir = path
	cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
	cmd.SysProcAttr = getSysProcAttr()
	return cmd, nil
}
1023783
func (f *Facade) AddCommand(name string, command cli.Command) {
	f.commands[name] = func() (cli.Command, error) {
		return command, nil
	}
}
617353
func Cmd(params base.Parameters) *subcommands.Command {
	return &subcommands.Command{
		UsageLine: "generate SCRIPT",
		ShortDesc: "interprets a high-level config, generating *.cfg files",
		LongDesc: `Interprets a high-level config, generating *.cfg files.

Writes generated configs to the directory given via -config-dir or via
lucicfg.config(config_dir=...) statement in the script. If it is '-', just
prints them to stdout.

If -validate is given, sends the generated config to LUCI Config service for
validation. This can also be done separately via 'validate' subcommand.

If the generation stage fails, doesn't overwrite any files on disk. If the
generation succeeds, but the validation fails, the new generated files are kept
on disk, so they can be manually examined for reasons they are invalid.
`,
		CommandRun: func() subcommands.CommandRun {
			gr := &generateRun{}
			gr.Init(params)
			gr.AddMetaFlags()
			gr.Flags.BoolVar(&gr.validate, "validate", false, "Validate the generate configs by sending them to LUCI Config")
			return gr
		},
	}
}
1053110
func (a *App) Command(cmd *Cmd) *App {
	if a.Commands == nil {
		a.Commands = Commands{}
	}

	a.Commands = append(a.Commands, cmd)
	return a
}
217219
func (s *SSD1306Driver) command(b byte) (err error) {
	if err = s.dcDriver.DigitalWrite(0); err != nil {
		return err
	}
	err = s.connection.Tx([]byte{b}, nil)
	return err
}
851882
func Daemon(d *daemon.Daemon) func(*icmd.Cmd) func() {
	return func(cmd *icmd.Cmd) func() {
		cmd.Command = append([]string{"--host", d.Sock()}, cmd.Command...)
		return nil
	}
}
176082
func CommandsCmd(root *cmds.Command) *cmds.Command {
	return &cmds.Command{
		Helptext: cmdkit.HelpText{
			Tagline:          "List all available commands.",
			ShortDescription: `Lists all available commands (and subcommands) and exits.`,
		},
		Options: []cmdkit.Option{
			cmdkit.BoolOption(flagsOptionName, "f", "Show command flags"),
		},
		Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
			rootCmd := cmd2outputCmd("ipfs", root)
			rootCmd.showOpts, _ = req.Options[flagsOptionName].(bool)
			return cmds.EmitOnce(res, &rootCmd)
		},
		Encoders: cmds.EncoderMap{
			cmds.Text: func(req *cmds.Request) func(io.Writer) cmds.Encoder {
				return func(w io.Writer) cmds.Encoder { return &commandEncoder{w} }
			},
		},
		Type: Command{},
	}
}
59134
func Cmd(cf *ChaincodeCmdFactory) *cobra.Command {
	addFlags(chaincodeCmd)

	chaincodeCmd.AddCommand(installCmd(cf))
	chaincodeCmd.AddCommand(instantiateCmd(cf))
	chaincodeCmd.AddCommand(invokeCmd(cf))
	chaincodeCmd.AddCommand(packageCmd(cf, nil))
	chaincodeCmd.AddCommand(queryCmd(cf))
	chaincodeCmd.AddCommand(signpackageCmd(cf))
	chaincodeCmd.AddCommand(upgradeCmd(cf))
	chaincodeCmd.AddCommand(listCmd(cf))

	return chaincodeCmd
}
937043
func Command(argv []string) int {
	deisctlMotd := prettyprint.DeisIfy("Deis Control Utility")
	usage := deisctlMotd + `
Usage: deisctl [options] <command> [<args>...]

Commands, use "deisctl help <command>" to learn more:
  config            set platform or component values
  dock              open an interactive shell on a container in the cluster
  help              show the help screen for a command
  install           install components, or the entire platform
  journal           print the log output of a component
  list              list installed components
  machines          list the current hosts in the cluster
  refresh-units     refresh unit files from GitHub
  restart           stop, then start components
  rolling-restart   perform a rolling restart of a Deis component (currently only router is supported)
  scale             grow or shrink the number of routers, registries or store gateways
  ssh               open an interactive shell on a machine in the cluster
  start             start components
  status            view status of components
  stop              stop components
  uninstall         uninstall components
  upgrade-prep      prepare a running cluster for upgrade
  upgrade-takeover  allow an upgrade to gracefully takeover a running cluster

Options:
  -h --help                   show this help screen
  --endpoint=<url>            etcd endpoint for fleet [default: http://127.0.0.1:4001]
  --etcd-cafile=<path>        etcd CA file authentication [default: ]
  --etcd-certfile=<path>      etcd cert file authentication [default: ]
  --etcd-key-prefix=<path>    keyspace for fleet data in etcd [default: /_coreos.com/fleet/]
  --etcd-keyfile=<path>       etcd key file authentication [default: ]
  --known-hosts-file=<path>   where to store remote fingerprints [default: ~/.ssh/known_hosts]
  --request-timeout=<secs>    seconds before a request is considered failed [default: 10.0]
  --ssh-timeout=<secs>        seconds before SSH connection is considered failed [default: 10.0]
  --strict-host-key-checking  verify SSH host keys [default: true]
  --tunnel=<host>             SSH tunnel for communication with fleet and etcd [default: ]
  --version                   print the version of deisctl
`
	// pre-parse command-line arguments
	argv, helpFlag := parseArgs(argv)
	// give docopt an optional final false arg so it doesn't call os.Exit()
	args, err := docopt.Parse(usage, argv, false, version.Version, true, false)

	if err != nil && err.Error() != "" {
		fmt.Println(err)
		return 1
	}

	if len(args) == 0 {
		return 0
	}

	command := args["<command>"].(string)
	setTunnel := true
	// "--help" and "refresh-units" doesn't need SSH tunneling
	if helpFlag || command == "refresh-units" {
		setTunnel = false
	}
	setGlobalFlags(args, setTunnel)
	// clean up the args so subcommands don't need to reparse them
	argv = removeGlobalArgs(argv)
	// construct a client
	c, err := client.NewClient("fleet")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return 1
	}
	// Dispatch the command, passing the argv through so subcommands can
	// re-parse it according to their usage strings.
	switch command {
	case "list":
		err = c.List(argv)
	case "machines":
		err = c.Machines(argv)
	case "scale":
		err = c.Scale(argv)
	case "start":
		err = c.Start(argv)
	case "restart":
		err = c.Restart(argv)
	case "stop":
		err = c.Stop(argv)
	case "status":
		err = c.Status(argv)
	case "journal":
		err = c.Journal(argv)
	case "install":
		err = c.Install(argv)
	case "uninstall":
		err = c.Uninstall(argv)
	case "config":
		err = c.Config(argv)
	case "refresh-units":
		err = c.RefreshUnits(argv)
	case "ssh":
		err = c.SSH(argv)
	case "dock":
		err = c.Dock(argv)
	case "upgrade-prep":
		err = c.UpgradePrep(argv)
	case "upgrade-takeover":
		err = c.UpgradeTakeover(argv)
	case "rolling-restart":
		err = c.RollingRestart(argv)
	case "help":
		fmt.Print(usage)
		return 0
	default:
		fmt.Println(`Found no matching command, try "deisctl help"
Usage: deisctl <command> [<args>...] [options]`)
		return 1
	}
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return 1
	}
	return 0
}
1284382
func (cfg *cloudConfig) RunCmds() []string {
	cmds, _ := cfg.attrs["runcmd"].([]string)
	return cmds
}
565388
func (a *Application) Command(name, help string) *CmdClause {
	return a.addCommand(name, help)
}
734339
func ExecCmd(name string, args ...string) (string, error) {
	cmd := exec.Command(name, args...)
	var stdout bytes.Buffer
	var stderr bytes.Buffer
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	if v, found := os.LookupEnv("XDG_RUNTIME_DIR"); found {
		cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", v))
	}

	err := cmd.Run()
	if err != nil {
		return "", fmt.Errorf("`%v %v` failed: %v %v (%v)", name, strings.Join(args, " "), stderr.String(), stdout.String(), err)
	}

	return stdout.String(), nil
}
801320
func NewDiffCommand(dockerCli command.Cli) *cobra.Command {
	var opts diffOptions

	return &cobra.Command{
		Use:   "diff CONTAINER",
		Short: "Inspect changes to files or directories on a container's filesystem",
		Args:  cli.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.container = args[0]
			return runDiff(dockerCli, &opts)
		},
	}
}
600991
func runCommand(cmd string) error {
	log.Debug("Running " + cmd)
	var c *exec.Cmd
	if runtime.GOOS == "windows" {
		c = exec.Command("cmd", "/C", cmd)
	} else {
		c = exec.Command("/bin/sh", "-c", cmd)
	}

	output, err := c.CombinedOutput()
	if err != nil {
		log.Error(fmt.Sprintf("%q", string(output)))
		return err
	}
	log.Debug(fmt.Sprintf("%q", string(output)))
	return nil
}
995529
func (c *ServerConn) cmd(expected int, format string, args ...interface{}) (int, string, error) {
	_, err := c.conn.Cmd(format, args...)
	if err != nil {
		return 0, "", err
	}

	return c.conn.ReadResponse(expected)
}