// Action triggers the action passed to it.
555396
func (mod *PastebinBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "post":
		title := ""
		content := ""
		expire := ""
		exposure := ""

		action.Options.Bind("title", &title)
		action.Options.Bind("content", &content)
		action.Options.Bind("expire", &expire)
		action.Options.Bind("exposure", &exposure)

		ret, err := mod.client.PasteAnonymous(content, title, "text", expire, exposure)
		if err != nil {
			mod.LogErrorf("Error occurred during posting to Pastebin: %v", err)
		} else {
			mod.Logln("Paste URL:", ret)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}
	return outs
}
128490
func (c *Change) Action() (merkletrie.Action, error) {
	if c.From == empty && c.To == empty {
		return merkletrie.Action(0),
			fmt.Errorf("malformed change: empty from and to")
	}
	if c.From == empty {
		return merkletrie.Insert, nil
	}
	if c.To == empty {
		return merkletrie.Delete, nil
	}

	return merkletrie.Modify, nil
}
395933
func (mod *DevrantBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "surprise":
		rant, err := mod.client.Surprise()
		if err != nil {
			mod.LogErrorf("Failed to fetch surprise rant: %v", err)
		}

		mod.triggerEvent(rant)

	case "weekly":
		rants, err := mod.client.WeeklyRants()
		if err != nil {
			mod.LogErrorf("Failed to fetch weekly rants: %v", err)
		}

		for _, v := range rants {
			mod.triggerEvent(v)
		}

	case "rant":
		limit := 0
		action.Options.Bind("limit", &limit)

		rants, err := mod.client.Rants("", limit, 0)
		if err != nil {
			mod.LogErrorf("Failed to fetch rants: %v", err)
		}

		for i := range rants {
			mod.triggerEvent(rants[i])
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
435229
func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "post_text":
		text := ""
		action.Options.Bind("text", &text)

		state := "published"
		err := mod.client.CreateText(mod.blogname, map[string]string{
			"body":  text,
			"state": state})
		if err != nil {
			mod.LogErrorf("Failed to post text: %v", err)
			return outs
		}
		ev := bees.Event{
			Bee:     mod.Name(),
			Name:    "posted",
			Options: []bees.Placeholder{},
		}
		mod.evchan <- ev

	case "post_quote":
		quote := ""
		source := ""
		action.Options.Bind("quote", &quote)
		action.Options.Bind("source", &source)

		state := "published"
		err := mod.client.CreateQuote(mod.blogname, map[string]string{
			"quote":  quote,
			"source": source,
			"state":  state})
		if err != nil {
			mod.LogErrorf("Failed to post quote: %v", err)
			return outs
		}
		ev := bees.Event{
			Bee:     mod.Name(),
			Name:    "posted",
			Options: []bees.Placeholder{},
		}
		mod.evchan <- ev

	case "follow":
		blogname := ""
		action.Options.Bind("blogname", &blogname)

		if err := mod.client.Follow(blogname); err != nil {
			mod.LogErrorf("Failed to follow blog: %v", err)
			return outs
		}

	case "unfollow":
		blogname := ""
		action.Options.Bind("blogname", &blogname)

		if err := mod.client.Unfollow(blogname); err != nil {
			mod.LogErrorf("Failed to unfollow blog: %v", err)
			return outs
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1196312
func (s *TasksListService) Actions(actions ...string) *TasksListService {
	s.actions = append(s.actions, actions...)
	return s
}
964850
func (s *TasksCancelService) Actions(actions ...string) *TasksCancelService {
	s.actions = append(s.actions, actions...)
	return s
}
1065456
func (c *Client) Action(tag names.ActionTag) (*Action, error) {
	result, err := c.getOneAction(tag)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &Action{
		name:   result.Action.Name,
		params: result.Action.Parameters,
	}, nil
}
953697
func (st *State) Action(tag names.ActionTag) (*Action, error) {
	result, err := st.getOneAction(&tag)
	if err != nil {
		return nil, err
	}
	return &Action{
		name:   result.Action.Name,
		params: result.Action.Parameters,
	}, nil
}
1038938
func (res *Resource) Action(actionName string, storage store.Get) {
	matcher := path.Join(patID, actionName)

	res.HandleFunc(
		pat.Get(matcher),
		func(w http.ResponseWriter, r *http.Request) {
			res.actionHandler(w, r, storage)
		},
	)

	res.addRoute(patch, matcher)
}
1023081
func (f *FlagClause) Action(action Action) *FlagClause {
	f.addAction(action)
	return f
}
1264283
func (mod *TwilioBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		body := ""
		action.Options.Bind("body", &body)

		_, err := twilio.NewMessage(mod.client, mod.fromNumber, mod.toNumber, twilio.Body(body))
		if err != nil {
			mod.LogErrorf("Error sending twilio SMS: %s", err)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1211545
func (mod *ExecBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "execute":
		var command string
		var stdin string

		action.Options.Bind("command", &command)
		action.Options.Bind("stdin", &stdin)
		mod.Logln("Executing locally: ", command)

		go func() {
			c := strings.Split(command, " ")
			cmd := exec.Command(c[0], c[1:]...)

			if stdin != "" {
				stdinPipe, err := cmd.StdinPipe()

				if err != nil {
					mod.LogFatal("Error creating stdinPipe for Cmd", err)
					return
				}

				go func() {
					io.WriteString(stdinPipe, stdin)
					stdinPipe.Close()
				}()
			}

			// read and print stdout
			outReader, err := cmd.StdoutPipe()
			if err != nil {
				mod.LogFatal("Error creating StdoutPipe for Cmd", err)
				return
			}
			outBuffer := []string{}
			outScanner := bufio.NewScanner(outReader)
			go func() {
				for outScanner.Scan() {
					foo := outScanner.Text()
					mod.Logln("execbee: std: | ", foo)
					outBuffer = append(outBuffer, foo)
				}
			}()

			// read and print stderr
			errReader, err := cmd.StderrPipe()
			if err != nil {
				mod.LogFatal("Error creating StderrPipe for Cmd", err)
				return
			}
			errBuffer := []string{}
			errScanner := bufio.NewScanner(errReader)
			go func() {
				for errScanner.Scan() {
					foo := errScanner.Text()
					mod.Logln("Err: | ", foo)
					errBuffer = append(errBuffer, foo)
				}
			}()

			err = cmd.Start()
			if err != nil {
				mod.LogFatal("Error starting Cmd", err)
			}

			err = cmd.Wait()
			if err != nil {
				mod.LogFatal("Error waiting for Cmd", err)
			}

			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "result",
				Options: []bees.Placeholder{
					{
						Name:  "stdout",
						Type:  "string",
						Value: strings.Join(outBuffer, "\n"),
					},
					{
						Name:  "stderr",
						Type:  "string",
						Value: strings.Join(errBuffer, "\n"),
					},
				},
			}
			mod.eventChan <- ev
		}()

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
896293
func (*DatabaseSettings) Actions(c context.Context) ([]portal.Action, error) {
	return nil, nil
}
331483
func (mod *SocketBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	var data string
	var addr string
	var port int

	action.Options.Bind("address", &addr)
	action.Options.Bind("port", &port)
	action.Options.Bind("data", &data)

	switch action.Name {
	case "send":
		// log.Println("Sending", data, "to", addr, port)

		sa, err := net.ResolveUDPAddr("udp", addr+":"+strconv.Itoa(port))
		if err != nil {
			log.Panicln(err)
		}

		conn, err := net.DialUDP("udp", nil, sa)
		if err != nil {
			log.Panicln(err)
		}

		defer conn.Close()
		_, err = conn.Write([]byte(data))
		if err != nil {
			log.Panicln(err)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1250393
func (s *SampledHTTPRequest) SetAction(v string) *SampledHTTPRequest {
	s.Action = &v
	return s
}
1343073
func (s *Change) SetAction(v string) *Change {
	s.Action = &v
	return s
}
693825
func (p *ParallelRunner) Action(ctx context.Context, path, name string) error {
	switch name {
	case actionNameRetry:
		// Extract the path relative to the root node.
		parts := strings.Split(path, "/")
		taskID := strings.Join(parts[2:], "/")
		return p.triggerRetry(taskID)
	case actionNameApproveFirstTask:
		p.mu.Lock()
		defer p.mu.Unlock()

		if p.firstTaskApproved != nil {
			close(p.firstTaskApproved)
			p.firstTaskApproved = nil
			return nil
		}
		return fmt.Errorf("ignored the approval action %v because no pending approval found: it might be already approved before", actionNameApproveFirstTask)
	case actionNameApproveRemainingTasks:
		p.mu.Lock()
		defer p.mu.Unlock()

		if p.remainingTasksApproved != nil {
			close(p.remainingTasksApproved)
			p.remainingTasksApproved = nil
			return nil
		}
		return fmt.Errorf("ignored the approval action %v because no pending approval found: it might be already approved before", actionNameApproveRemainingTasks)
	default:
		return fmt.Errorf("unknown action: %v", name)
	}
}