// actionDecorator is used to add additional information and error handling
// to command actions.
772574
func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error {
	return func(c *cli.Context) error {
		if err := f(c); err != nil {
			s, ok := status.FromError(err)

			// If it's a command for the UnlockerService (like
			// 'create' or 'unlock') but the wallet is already
			// unlocked, then these methods aren't recognized any
			// more because this service is shut down after
			// successful unlock. That's why the code
			// 'Unimplemented' means something different for these
			// two commands.
			if s.Code() == codes.Unimplemented &&
				(c.Command.Name == "create" ||
					c.Command.Name == "unlock") {
				return fmt.Errorf("Wallet is already unlocked")
			}

			// lnd might be active, but not possible to contact
			// using RPC if the wallet is encrypted. If we get
			// error code Unimplemented, it means that lnd is
			// running, but the RPC server is not active yet (only
			// WalletUnlocker server active) and most likely this
			// is because of an encrypted wallet.
			if ok && s.Code() == codes.Unimplemented {
				return fmt.Errorf("Wallet is encrypted. " +
					"Please unlock using 'lncli unlock', " +
					"or set password using 'lncli create'" +
					" if this is the first time starting " +
					"lnd.")
			}
			return err
		}
		return nil
	}
}
2391
func Action(a func(*cli.Context)) Option {
	return func(o *Options) {
		o.Action = a
	}
}
712506
func (ctx *HookContext) finalizeAction(err, unhandledErr error) error {
	// TODO (binary132): synchronize with gsamfira's reboot logic
	message := ctx.actionData.ResultsMessage
	results := ctx.actionData.ResultsMap
	tag := ctx.actionData.Tag
	status := params.ActionCompleted
	if ctx.actionData.Failed {
		status = params.ActionFailed
	}

	// If we had an action error, we'll simply encapsulate it in the response
	// and discard the error state.  Actions should not error the uniter.
	if err != nil {
		message = err.Error()
		if charmrunner.IsMissingHookError(err) {
			message = fmt.Sprintf("action not implemented on unit %q", ctx.unitName)
		}
		status = params.ActionFailed
	}

	callErr := ctx.state.ActionFinish(tag, status, results, message)
	if callErr != nil {
		unhandledErr = errors.Wrap(unhandledErr, callErr)
	}
	return unhandledErr
}
546633
func (v *Activatable) SetRelatedAction(action *Action) {
	deprecated_since(3, 10, 0, "gtk_activatable_set_related_action()")
	C.gtk_activatable_set_related_action(ACTIVATABLE(v), ACTION(action))
}
247032
func (c *Context) Action(ctl string, act string) (err error) {
	a := c.Module.Wrapper(`controller.` + ctl)
	if a == nil {
		return c.Atoe(`Controller "` + ctl + `" does not exist.`)
	}
	k := `webx.controller.reflect.type:` + ctl
	var e reflect.Type
	if t, ok := c.Get(k).(reflect.Type); ok {
		e = t
	} else {
		e = reflect.Indirect(reflect.ValueOf(a.Controller)).Type()
		c.Set(k, e)
	}
	return a.Exec(c, e, act)
}
1328357
func (w *Ware) Action(handler Handler) {
	validateHandler(handler)
	w.action = handler
}
1364379
func (a *ActDepend) ChainAction(f ActionInterface) ActionInterface {
	return a.current().ChainAction(f)
}
98062
func (opc *operationCallbacks) FailAction(actionId, message string) error {
	if !names.IsValidAction(actionId) {
		return errors.Errorf("invalid action id %q", actionId)
	}
	tag := names.NewActionTag(actionId)
	err := opc.u.st.ActionFinish(tag, params.ActionFailed, nil, message)
	if params.IsCodeNotFoundOrCodeUnauthorized(err) {
		err = nil
	}
	return err
}
452475
func (mod *PrometheusBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}
	switch action.Name {
	case "counter_inc":
		var label string
		action.Options.Bind("label", &label)
		c, err := mod.counter.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error incrementing counter: %v", err)
		} else {
			c.Inc()
		}
	case "counter_add":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		c, err := mod.counter.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error adding to counter: %v", err)
		} else {
			c.Add(value)
		}
	case "gauge_set":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error setting gauge: %v", err)
		} else {
			g.Set(value)
		}
	case "gauge_inc":
		var label string
		action.Options.Bind("label", &label)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error incrementing gauge: %v", err)
		} else {
			g.Inc()
		}
	case "gauge_dec":
		var label string
		action.Options.Bind("label", &label)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error decrementing gauge: %v", err)
		} else {
			g.Dec()
		}
	case "gauge_add":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error adding to gauge: %v", err)
		} else {
			g.Add(value)
		}
	case "gauge_sub":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error subtracting from gauge: %v", err)
		} else {
			g.Sub(value)
		}
	case "gauge_set_to_current_time":
		var label string
		action.Options.Bind("label", &label)
		g, err := mod.gauge.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error setting gauge to current time: %v", err)
		} else {
			g.SetToCurrentTime()
		}
	case "histogram_observe":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		h, err := mod.histogram.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error observing value for histogram: %v", err)
		} else {
			h.Observe(value)
		}
	case "summary_observe":
		var label string
		var value float64
		action.Options.Bind("label", &label)
		action.Options.Bind("value", &value)
		s, err := mod.summary.GetMetricWithLabelValues(label)
		if err != nil {
			mod.LogErrorf("Error observing value for summary: %v", err)
		} else {
			s.Observe(value)
		}
	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
}
1150721
func (ca *CompositeAction) Add(a Action) {
	ca.actions = append(ca.actions, a)
}
396150
func NewActionFailCommand(ctx Context) (cmd.Command, error) {
	return &ActionFailCommand{ctx: ctx}, nil
}
415740
func (w Wrapper) WrapAction(action func()) {
	if w.interactiveMode {
		w.spinner.Start()
		action()
		w.spinner.Stop()
	} else {
		message := w.spinner.message
		if !strings.HasSuffix(message, ".") {
			message = message + "..."
		}
		if _, err := fmt.Fprintln(w.spinner.writer, message); err != nil {
			fmt.Printf("failed to print message: %s, error: %s", message, err)
		}
		action()
	}
}
1131471
func WrapAction(action cli.ActionFunc) cli.ActionFunc {
	if action == nil {
		return nil
	}

	return func(c *cli.Context) (err error) {
		if err = action(c); err != nil {
			switch err.(type) {
			case cli.ExitCoder:
				return
			default:
				var message string
				formatter := errutil.NewConsoleFormatter("; ")
				if message, err = formatter.FormatSkip(err, 1); err != nil {
					panic(err)
				}
				return cli.Exit(message, 1)
			}
		}
		return
	}
}
294139
func (st *State) ActionBegin(tag names.ActionTag) error {
	var outcome params.ErrorResults

	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag.String()},
		},
	}

	err := st.facade.FacadeCall("BeginActions", args, &outcome)
	if err != nil {
		return err
	}
	if len(outcome.Results) != 1 {
		return fmt.Errorf("expected 1 result, got %d", len(outcome.Results))
	}
	result := outcome.Results[0]
	if result.Error != nil {
		return result.Error
	}
	return nil
}
1064780
func NewCustomAction(f func(manager Manager, filters ...Filter) error, filters ...Filter) Action {
	return &action{action: CustomAction, filters: filters, f: f}
}
939021
func (r *RepositoryVulnerabilityAlertEvent) GetAction() string {
	if r == nil || r.Action == nil {
		return ""
	}
	return *r.Action
}