// Execute executes the given command line.
428172
func (cli *SeesawCLI) Execute(cmdline string) error {
	cmd, subcmds, _, args := FindCommand(cmdline)
	if cmd != nil {
		return cmd.function(cli, args)
	}
	if subcmds != nil {
		return errors.New("Incomplete command.")
	}
	return errors.New("Unknown command.")
}
1338069
func (pc *ConfigCmd) Execute(conf common.Config) error {
	if pc.server == nil || *pc.server == "" {
		return errors.New("no server specified")
	}
	if pc.channel == nil || *pc.channel == "" {
		return errors.New("no channel specified")
	}

	server := *pc.server
	channel := *pc.channel

	req := discovery.NewRequest().OfChannel(channel).AddConfigQuery()
	res, err := pc.stub.Send(server, conf, req)
	if err != nil {
		return err
	}
	return pc.parser.ParseResponse(channel, res)
}
1268476
func (s *SystemService) Execute(args []string, changeReq <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) {
	const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
	changes <- svc.Status{State: svc.StartPending}

	errChannel := make(chan int, 1)

	go func() {
		err := s.Cmd(s.Args)
		errChannel <- err
	}()

	changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}

	for {
		select {
		case r := <-changeReq:
			switch r.Cmd {
			case svc.Interrogate:
				changes <- r.CurrentStatus
			case svc.Stop, svc.Shutdown:
				changes <- svc.Status{State: svc.StopPending}
				return false, 0
			}
		case err := <-errChannel:
			return false, uint32(err)
		}
	}
}
957664
func Execute(args []string) Response {
	hugoCmd := newCommandsBuilder().addAll().build()
	cmd := hugoCmd.getCommand()
	cmd.SetArgs(args)

	c, err := cmd.ExecuteC()

	var resp Response

	if c == cmd && hugoCmd.c != nil {
		// Root command executed
		resp.Result = hugoCmd.c.hugo
	}

	if err == nil {
		errCount := int(loggers.GlobalErrorCounter.Count())
		if errCount > 0 {
			err = fmt.Errorf("logged %d errors", errCount)
		} else if resp.Result != nil {
			errCount = resp.Result.NumLogErrors()
			if errCount > 0 {
				err = fmt.Errorf("logged %d errors", errCount)
			}
		}

	}

	resp.Err = err
	resp.Cmd = c

	return resp
}
132884
func (h *DefaultPluginHandler) Execute(executablePath string, cmdArgs, environment []string) error {
	return syscall.Exec(executablePath, cmdArgs, environment)
}
619499
func Execute(client *SSHForwardingClient, cmd string) (error, int) {
	session, finalize, err := makeSession(client)
	if err != nil {
		return err, -1
	}

	defer finalize()

	session.Start(cmd)

	err = session.Wait()
	// the command ran and exited successfully
	if err == nil {
		return nil, 0
	}
	// if the session terminated normally, err should be ExitError; in that
	// case, return nil error and actual exit status of command
	if werr, ok := err.(*gossh.ExitError); ok {
		return nil, werr.ExitStatus()
	}
	// otherwise, we had an actual SSH error
	return err, -1
}
477633
func (c *Cluster) Execute(cmd *Command) (*Reply, error) {
	if len(cmd.args) < 1 {
		return nil, ErrNoKey
	}
	key := string(convertString(cmd.args[0]))
	pool := c.shards[DefaultShardStrategy(key, len(c.shards))]
	conn, err := pool.Acquire()
	if err != nil {
		return nil, err
	}
	if conn == nil {
		return nil, ErrNotConnected
	}
	defer pool.Release(conn)
	return cmd.Run(conn)
}
988558
func (d *deploy) Execute(state State) (*State, error) {
	if err := d.deployer.Deploy(); err == charm.ErrConflict {
		return nil, NewDeployConflictError(d.charmURL)
	} else if err != nil {
		return nil, errors.Trace(err)
	}
	return d.getState(state, Done), nil
}
331154
func (c *DriverSet) Execute(args []string) error {
	App.initializeLogging()
	path := string(c.Args.Path)
	if _, err := InitDriverIfExists(path); err == volume.ErrDriverNotInit {
		log.Fatalf("Driver not initialized. Use `%s driver init %s TYPE [OPTIONS]`", "."+App.name, path)
	}
	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}
	if err := ioutil.WriteFile(filepath.Join(usr.HomeDir, App.name), []byte(path), 0644); err != nil {
		log.Fatal(err)
	}
	return nil
}
1072142
func (p *FetchJvnCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
	c.Conf.Debug = p.debug
	c.Conf.Quiet = p.quiet
	c.Conf.DebugSQL = p.debugSQL
	c.Conf.DBPath = p.dbpath
	c.Conf.DBType = p.dbtype
	//  c.Conf.DumpPath = p.dumpPath
	c.Conf.HTTPProxy = p.httpProxy

	log.SetLogger(p.logDir, c.Conf.Quiet, c.Conf.Debug, p.logJSON)
	if !c.Conf.Validate() {
		return subcommands.ExitUsageError
	}

	years := []int{}
	thisYear := time.Now().Year()

	switch {
	case p.latest:
		years = append(years, c.Latest)
	case p.last2Y:
		for i := 0; i < 2; i++ {
			years = append(years, thisYear-i)
		}
		years = append(years, c.Latest)
	case p.years:
		if len(f.Args()) == 0 {
			log.Errorf("Specify years to fetch (from 1998 to %d)", thisYear)
			return subcommands.ExitUsageError
		}
		for _, arg := range f.Args() {
			year, err := strconv.Atoi(arg)
			if err != nil || year < 1998 || time.Now().Year() < year {
				log.Errorf("Specify years to fetch (from 1998 to %d), arg: %s", thisYear, arg)
				return subcommands.ExitUsageError
			}
			found := false
			for _, y := range years {
				if y == year {
					found = true
					break
				}
			}
			if !found {
				years = append(years, year)
			}
		}
		years = append(years, c.Latest)
	default:
		log.Errorf("specify -latest, -last2y or -years")
		return subcommands.ExitUsageError
	}

	driver, locked, err := db.NewDB(c.Conf.DBType, c.Conf.DBPath, c.Conf.DebugSQL)
	if err != nil {
		if locked {
			log.Errorf("Failed to Open DB. Close DB connection before fetching: %s", err)
			return subcommands.ExitFailure
		}
		log.Errorf("%s", err)
		return subcommands.ExitFailure
	}
	defer driver.CloseDB()

	metas, err := jvn.FetchLatestFeedMeta(driver, years)
	if err != nil {
		log.Errorf("%s", err)
		return subcommands.ExitFailure
	}

	if len(metas) == 0 {
		log.Errorf("No meta files fetched")
		return subcommands.ExitFailure
	}

	//TODO use meta.Status()
	needUpdates := []models.FeedMeta{}
	for _, m := range metas {
		if m.Newly() {
			needUpdates = append(needUpdates, m)
			log.Infof("Newly     : %s", m.URL)
		} else if m.OutDated() {
			needUpdates = append(needUpdates, m)
			log.Infof("Outdated  : %s", m.URL)
		} else {
			log.Infof("Up to date: %s", m.URL)
		}
	}

	if len(needUpdates) == 0 {
		log.Infof("Already up to date")
		return subcommands.ExitSuccess
	}

	log.Infof("Fetcling CVE information from JVN.")
	cves, err := jvn.FetchConvert(needUpdates)
	if err != nil {
		log.Errorf("Failed to fetch JVN: %s", err)
		return subcommands.ExitFailure
	}
	log.Infof("Fetched %d CVEs", len(cves))

	log.Infof("Inserting JVN into DB (%s).", driver.Name())
	if err := driver.InsertJvn(cves); err != nil {
		log.Fatalf("Failed to insert. dbpath: %s, err: %s", c.Conf.DBPath, err)
		return subcommands.ExitFailure
	}

	if err := jvn.UpdateMeta(driver, needUpdates); err != nil {
		log.Fatalf("Failed to Update meta. dbpath: %s, err: %s", c.Conf.DBPath, err)
		return subcommands.ExitFailure
	}
	return subcommands.ExitSuccess
}
937998
func (client *QueryClient) Execute(query string, bindvars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
	return client.ExecuteWithOptions(query, bindvars, &querypb.ExecuteOptions{IncludedFields: querypb.ExecuteOptions_ALL})
}
542329
func (c *ExpandSpec) Execute(args []string) error {
	if len(args) != 1 {
		return errors.New("The expand command requires the single swagger document url to be specified")
	}

	swaggerDoc := args[0]
	specDoc, err := loads.Spec(swaggerDoc)
	if err != nil {
		return err
	}

	exp, err := specDoc.Expanded()
	if err != nil {
		return err
	}

	return writeToFile(exp.Spec(), !c.Compact, c.Format, string(c.Output))
}
1330549
func (c *QueryRead) Execute(args []string) error {
	return c.doQueryOp(ShellQueryClient.Read, c.Args.EntityName, c.Args.Queries, 1)
}
1072270
func (s *Script) Execute(conn *Conn, keyCount int, keysAndArgs ...interface{}) (*Reply, error) {
	s.lock.RLock()
	defer s.lock.RUnlock()
	if s.body == "" {
		return nil, ErrEmptyScript
	}
	args := make([]interface{}, len(keysAndArgs)+2)
	args[0] = s.sha
	args[1] = keyCount
	for i := range keysAndArgs {
		args[i+2] = keysAndArgs[i]
	}
	rep, err := NewCommand("EVALSHA", args...).Run(conn)
	if err != nil {
		return nil, err
	}
	if !rep.IsError() {
		return rep, nil
	}
	errorMessage, _ := rep.Error()
	if !strings.HasPrefix(errorMessage, "NOSCRIPT") {
		return rep, nil
	}
	args[0] = s.body
	return NewCommand("EVAL", args...).Run(conn)
}
317304
func (b *Bus) Execute(command Command) (result interface{}, err error) {
	return b.ExecuteContext(context.Background(), command)
}
604240
func Execute(ctx context.Context, executeWaitGroup *sync.WaitGroup, stat *pb.InstructionStat,
	name string, command *exec.Cmd,
	reader io.Reader, writer io.Writer, prevIsPipe, isPipe bool, closeOutput bool,
	errWriter io.Writer) error {

	defer func() {
		executeWaitGroup.Done()
		if closeOutput {
			if c, ok := writer.(io.Closer); ok {
				c.Close()
			}
		}
	}()

	var wg sync.WaitGroup

	if reader != nil {
		if prevIsPipe && isPipe {
			// println("step", name, "input is lines->lines")
			command.Stdin = reader
		} else if !prevIsPipe && !isPipe {
			// println("step", name, "input is msgpack->msgpack")
			command.Stdin = reader
		} else {
			inputWriter, stdinErr := command.StdinPipe()
			if stdinErr != nil {
				fmt.Fprintf(errWriter, "Failed to open StdinPipe: %v", stdinErr)
			} else {
				wg.Add(1)
				if !prevIsPipe && isPipe {
					// println("step", name, "input is msgpack->lines")
					go ChannelToLineWriter(&wg, stat, name, reader, inputWriter, errWriter)
				} else {
					// println("step", name, "input is lines->msgpack")
					go LineReaderToChannel(&wg, stat, name, reader, inputWriter, true, errWriter)
				}
			}
		}
	}

	command.Stdout = writer

	command.Stderr = errWriter

	// println(name, "starting...", strings.Join(command.Args, ","))

	if startError := command.Start(); startError != nil {
		return fmt.Errorf("Start error %v: %v\n", startError, command)
	}

	// fmt.Printf("%s Command is waiting..\n", name)
	errChan := make(chan error)
	go func() {
		wg.Wait()
		waitError := command.Wait()
		if waitError != nil {
			waitError = fmt.Errorf("%s Wait error %+v.\n", name, waitError)
		}
		errChan <- waitError
	}()

	// defer fmt.Printf("%s Command is finished.\n", name)

	select {
	case <-ctx.Done():
		println("cancel process", command.Process.Pid, name, "...")
		command.Process.Kill()
		command.Process.Release()
		return ctx.Err()
	case err := <-errChan:
		return err
	}

}
377273
func (cmd *importCmd) Execute(args []string) error {
	// Setup the global config options and ensure they are valid.
	if err := setupGlobalConfig(); err != nil {
		return err
	}

	// Ensure the specified block file exists.
	if !fileExists(cmd.InFile) {
		str := "The specified block file [%v] does not exist"
		return fmt.Errorf(str, cmd.InFile)
	}

	// Load the block database.
	db, err := loadBlockDB()
	if err != nil {
		return err
	}
	defer db.Close()

	// Ensure the database is sync'd and closed on Ctrl+C.
	addInterruptHandler(func() {
		log.Infof("Gracefully shutting down the database...")
		db.Close()
	})

	fi, err := os.Open(importCfg.InFile)
	if err != nil {
		return err
	}
	defer fi.Close()

	// Create a block importer for the database and input file and start it.
	// The results channel returned from start will contain an error if
	// anything went wrong.
	importer := newBlockImporter(db, fi)

	// Perform the import asynchronously and signal the main goroutine when
	// done.  This allows blocks to be processed and read in parallel.  The
	// results channel returned from Import contains the statistics about
	// the import including an error if something went wrong.  This is done
	// in a separate goroutine rather than waiting directly so the main
	// goroutine can be signaled for shutdown by either completion, error,
	// or from the main interrupt handler.  This is necessary since the main
	// goroutine must be kept running long enough for the interrupt handler
	// goroutine to finish.
	go func() {
		log.Info("Starting import")
		resultsChan := importer.Import()
		results := <-resultsChan
		if results.err != nil {
			dbErr, ok := results.err.(database.Error)
			if !ok || ok && dbErr.ErrorCode != database.ErrDbNotOpen {
				shutdownChannel <- results.err
				return
			}
		}

		log.Infof("Processed a total of %d blocks (%d imported, %d "+
			"already known)", results.blocksProcessed,
			results.blocksImported,
			results.blocksProcessed-results.blocksImported)
		shutdownChannel <- nil
	}()

	// Wait for shutdown signal from either a normal completion or from the
	// interrupt handler.
	err = <-shutdownChannel
	return err
}