Skip to content

Extra flag mode and custom validator error message support added

Compare
Choose a tag to compare
@tiborsimon tiborsimon released this 30 May 07:23
· 28 commits to master since this release

Extra flag mode

From now, you can ask for a flag structure any time by using a second output variable during the parser API function call:

function ret = my_function( varargin )

    params.a = 0;
    params.b = 0;
    params.c = 0;

    [params, flags] = simple_input_parser(flags, varargin);

    % if a value was parsed, it's corresponding field in the flags structure will 
    % be assigned to one unlike the previous flag mode, it is not necessary to 
    % truncate the varargin parameter to it's firts element the flag generation 
    % will work during other modes as well

    % further functionalities

end

Cutom validator error message

A minor upgrade was applied to the custom validator functions as well for supporting custom error messages.
IMPORTANT : error messages are mandatory output variables for the validator functions

function ret = my_function( varargin )

    params.a = 0;
    params.b = 0;
    params.c = 0;

    function [validflag, errormsg] = validate_c(value)
        errormsg = 'Parameter c has to be greater than 1..';
        validflag = value > 1;
    end

    validators.b = @validate_c;

    params = simple_input_parser(params, varargin, validators);

    % further functionalities

end