Command represents an operation that can be performed on a CrowdSec hub item. Each concrete implementation defines a Prepare() method to check for errors and preconditions, decide which sub-commands are required (like installing dependencies) and add them to the action plan.
| 23 | // Each concrete implementation defines a Prepare() method to check for errors and preconditions, |
| 24 | // decide which sub-commands are required (like installing dependencies) and add them to the action plan. |
| 25 | type Command interface { |
| 26 | // Prepare sets up the command for execution within the given |
| 27 | // ActionPlan. It may add additional commands to the ActionPlan based |
| 28 | // on dependencies or prerequisites. Returns a boolean indicating |
| 29 | // whether the command execution should be skipped (it can be |
| 30 | // redundant, like installing something that is already installed) and |
| 31 | // an error if the preparation failed. |
| 32 | // NOTE: Returning an error will bubble up from the plan.AddCommand() method, |
| 33 | // but Prepare() might already have modified the plan's command slice. |
| 34 | Prepare(plan *ActionPlan) (bool, error) |
| 35 | |
| 36 | // Run executes the command within the provided context and ActionPlan. |
| 37 | // It performs the actual operation and returns an error if execution fails. |
| 38 | // NOTE: Returning an error will currently stop the execution of the action plan. |
| 39 | Run(ctx context.Context, plan *ActionPlan) error |
| 40 | |
| 41 | // OperationType returns a unique string representing the type of operation to perform |
| 42 | // (e.g., "download", "enable"). |
| 43 | OperationType() string |
| 44 | |
| 45 | // ItemType returns the type of item the operation is performed on |
| 46 | // (e.g., "collections"). Used in confirmation prompt and dry-run. |
| 47 | ItemType() string |
| 48 | |
| 49 | // Detail provides further details on the operation, |
| 50 | // such as the item's name and version. |
| 51 | Detail() string |
| 52 | } |
| 53 | |
| 54 | // UniqueKey generates a unique string key for a Command based on its operation type, item type, and detail. |
| 55 | // Is is used to avoid adding duplicate commands to the action plan. |
no outgoing calls
no test coverage detected
searching dependent graphs…