Trig error occurence and print meaningful message.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(command_line_argument), | intent(inout) | :: | self |
CLA data. |
||
integer(kind=I4P), | intent(in) | :: | error |
Error occurred. |
||
character(len=*), | intent(in), | optional | :: | pref |
Prefixing string. |
|
character(len=*), | intent(in), | optional | :: | switch |
CLA switch name. |
|
character(len=*), | intent(in), | optional | :: | val_str |
Value string. |
|
character(len=*), | intent(in), | optional | :: | log_value |
Logical value to be casted. |
subroutine errored(self, error, pref, switch, val_str, log_value) !< Trig error occurence and print meaningful message. class(command_line_argument), intent(inout) :: self !< CLA data. integer(I4P), intent(in) :: error !< Error occurred. character(*), optional, intent(in) :: pref !< Prefixing string. character(*), optional, intent(in) :: switch !< CLA switch name. character(*), optional, intent(in) :: val_str !< Value string. character(*), optional, intent(in) :: log_value !< Logical value to be casted. character(len=:), allocatable :: prefd !< Prefixing string. self%error = error if (self%error/=0) then prefd = '' ; if (present(pref)) prefd = pref prefd = prefd//self%progname//': '//colorize('error', color_fg=self%error_color, style=self%error_style) select case(self%error) case(ERROR_OPTIONAL_NO_DEF) if (self%is_positional) then self%error_message = prefd//': "'//trim(str(n=self%position))//'-th" positional option has not a default value!' else self%error_message = prefd//': named option "'//self%switch//'" has not a default value!' endif case(ERROR_REQUIRED_M_EXCLUDE) self%error_message = prefd//': named option "'//self%switch//'" cannot exclude others'//& ', it being required, only optional ones can!' case(ERROR_POSITIONAL_M_EXCLUDE) self%error_message = prefd//': "'//trim(str(n=self%position))//& '-th" positional option cannot exclude others, only optional named options can!' case(ERROR_NAMED_NO_NAME) self%error_message = prefd//': a non positional optiona must have a switch name!' case(ERROR_POSITIONAL_NO_POSITION) self%error_message = prefd//': a positional option must have a position number different from 0!' case(ERROR_POSITIONAL_NO_STORE) self%error_message = prefd//': a positional option must have action set to "'//action_store//'"!' case(ERROR_M_EXCLUDE) self%error_message = prefd//': the options "'//self%switch//'" and "'//self%m_exclude//& '" are mutually exclusive, but both have been passed!' case(ERROR_NOT_IN_CHOICES) if (self%is_positional) then self%error_message = prefd//': value of "'//trim(str(n=self%position))//& '-th" positional option must be chosen in:' else self%error_message = prefd//': value of named option "'//self%switch//'" must be chosen in: ' endif self%error_message = self%error_message//'('//self%choices//')' self%error_message = self%error_message//' but "'//trim(val_str)//'" has been passed!' case(ERROR_MISSING_REQUIRED) if (.not.self%is_positional) then self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//'" is required!' else self%error_message = prefd//': "'//trim(str(self%position, .true.))//'-th" positional option is required!' endif case(ERROR_CASTING_LOGICAL) self%error_message = prefd//': cannot convert "'//log_value//'" of option "'//self%switch//'" to logical type!' case(ERROR_CHOICES_LOGICAL) self%error_message = prefd//': cannot use "choices" value check for option "'//self%switch//& '" it being of logical type! The choices are limited to ".true." or ".false." by definition!' case(ERROR_NO_LIST) if (.not.self%is_positional) then self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" has not "nargs" value but an array has been passed to "get" method!' else self%error_message = prefd//': "'//trim(str(self%position, .true.))//'-th" positional option '//& 'has not "nargs" value but an array has been passed to "get" method!' endif case(ERROR_NARGS_INSUFFICIENT) if (.not.self%is_positional) then if (self%nargs=='+') then self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" requires at least 1 argument but no one remains!' else self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//'" requires '//& trim(adjustl(self%nargs))//' arguments but no enough ones remain!' endif else if (self%nargs=='+') then self%error_message = prefd//': "'//trim(str(self%position, .true.))//& '-th" positional option requires at least 1 argument but no one remains' else self%error_message = prefd//': "'//trim(str(self%position, .true.))//'-th" positional option requires '//& trim(adjustl(self%nargs))//' arguments but no enough ones remain!' endif endif case(ERROR_VALUE_MISSING) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//'" needs a value that is not passed!' case(ERROR_UNKNOWN) self%error_message = prefd//': switch "'//trim(adjustl(switch))//'" is unknown!' case(ERROR_ENVVAR_POSITIONAL) self%error_message = prefd//': "'//trim(str(self%position, .true.))//'-th" positional option '//& 'has "envvar" value that is not allowed for positional option!' case(ERROR_ENVVAR_NOT_STORE) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" is an envvar with action different from "'//action_store//'" that is not allowed!' case(ERROR_ENVVAR_NARGS) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" is an envvar that is not allowed for list valued option!' case(ERROR_STORE_STAR_POSITIONAL) self%error_message = prefd//': "'//trim(str(self%position, .true.))//'-th" positional option '//& 'has "'//action_store_star//'" action that is not allowed for positional option!' case(ERROR_STORE_STAR_NARGS) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" has "'//action_store_star//'" action that is not allowed for list valued option!' case(ERROR_STORE_STAR_ENVVAR) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//& '" has "'//action_store_star//'" action that is not allowed for environment variable option!' case(ERROR_ACTION_UNKNOWN) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//'" has unknown "'//self%act//'" action!' case(ERROR_DUPLICATED_CLAS) self%error_message = prefd//': switch "'//trim(adjustl(switch))//'" has been passed more than once!' case(ERROR_MISSING_REQUIRED_VAL) self%error_message = prefd//': named option "'//trim(adjustl(self%switch))//'" requires a value that is not passed!' endselect call self%print_error_message endif endsubroutine errored