Pre-Execution Hooks

Pre-Execution Hooks

OnPreEnsure fires after parsing but before constraint evaluation. Use it to manipulate raw argument strings before type conversion runs:

cmdDef.OnPreEnsure = (cmd) =>
{
    var dayOpt = cmd.GetOption(o => o.Flag == "--day");
    if (int.TryParse(dayOpt.Argument, out int shift))
        dayOpt.OverrideArgument(DateTime.Today.AddDays(shift).ToString("yyyy-MM-dd"));
};

In this example, an integer offset (0 = today, -1 = yesterday, 1 = tomorrow) is accepted in place of a full date string. The hook rewrites the raw argument before the DateOnly constraint runs.