Creating Resolutions
Once a class implementing ICheck
has identified that the current user's machine is not correctly set up for the plugin or project,
it is the job of resolutions (classes implementing IResolution
) to fix the issue.
Resolutions should be written so that a user has to do as little as possible to fix the issue discovered by an ICheck
class.
For example, if it is the job of a class implementing ICheck
to verify that a user's machine has Node.js installed,
when it fails it could present the user with different resolutions all to install Node.js in different ways.
Creating a Resolution
Using a similar API to ICheck
s, a resolution is a class that implements the IResolution
interface.
public interface IResolution
{
string Name { get; }
Task<ResolutionSuccessAction> Run(CheckFailureException checkFailureException);
}
- The
Name
property is a friendly name for the resolution that will be displayed to the user - The
Run
method is where the functionality of the resolution is implemented
Return Type
Once a resolution has been successful in resolving the issue discovered from a check, the return type will determine how the GetSetUp CLI responds.
The return value is a value from the ResolutionSuccessAction
enum.
public enum ResolutionSuccessAction
{
RetryCheck,
Continue
}
RetryCheck
will prompt the GetSetUp CLI to re-run the check that failed to see if the resolution was successfulContinue
will prompt the GetSetUp CLI to continue running the following checks, blindly assuming the check was successful
Typically we suggest returning RetryCheck
from a resolution, to ensure that any further issues are discovered and resolved before continuing.
A check can only be retried twice, for a total of three attempts. After that, the resolution will be marked as failed in the results summary and when the CLI exits it will use a non-zero exit code.
Throwing Exceptions
Even if a resolution is successful, the continuation of other checks (from either the same plugin or others) is not always the desired next behaviour.
Associating Resolutions with Checks
Resolutions are associated to checks using the WithResolution
builder method chained into CreateCheck
within your plugin's ConfigureServices
method.
public class MyPlugin : IPlugin
{
public void ConfigureServices(IServiceCollection services)
{
services
.CreateCheck<Check>()
.WithResolution<ResolutionOne>()
.WithResolution<ResolutionTwo>();
}
}
In the example above, if the Check
class throws a CheckFailureException
, the GetSetUp CLI will prompt the user to run either
the ResolutionOne
or ResolutionTwo
resolution.