diff --git a/example/example.f90 b/example/example.f90 index 8cfcd10..68caf8b 100644 --- a/example/example.f90 +++ b/example/example.f90 @@ -44,4 +44,4 @@ program subcommand_example call args%get("message", message) print *, "Committing: ", trim(message) end select -end program subcommand_example \ No newline at end of file +end program subcommand_example diff --git a/src/fclap.f90 b/src/fclap.f90 index fd2ec4b..bb4ccab 100644 --- a/src/fclap.f90 +++ b/src/fclap.f90 @@ -57,7 +57,7 @@ module fclap use fclap_version, only: get_fclap_version, fclap_version_compact, & fclap_version_string - implicit none + implicit none(type) private ! Public types - main user-facing API diff --git a/src/fclap/fclap_actions.f90 b/src/fclap/fclap_actions.f90 index 6111de7..d16fd00 100644 --- a/src/fclap/fclap_actions.f90 +++ b/src/fclap/fclap_actions.f90 @@ -410,7 +410,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (int_val < int_bound) then - call error%init("value must not be less than " // trim(self%bound_str), values(1)) + call error%init( & + "value must not be less than " // trim(self%bound_str), & + values(1)) return end if call args%set_integer(self%dest, int_val) @@ -427,7 +429,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (real_val < real_bound) then - call error%init("value must not be less than " // trim(self%bound_str), values(1)) + call error%init( & + "value must not be less than " // trim(self%bound_str), & + values(1)) return end if store_real_val = real(real_val) @@ -442,7 +446,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (str_len < int_bound) then - call error%init("string length must not be less than " // trim(self%bound_str), values(1)) + call error%init( & + "string length must not be less than " // trim(self%bound_str), & + values(1)) return end if call args%set_string(self%dest, values(1)) @@ -468,7 +474,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (int_val > int_bound) then - call error%init("value must not be bigger than " // trim(self%bound_str), values(1)) + call error%init( & + "value must not be bigger than " // trim(self%bound_str), & + values(1)) return end if call args%set_integer(self%dest, int_val) @@ -485,7 +493,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (real_val > real_bound) then - call error%init("value must not be bigger than " // trim(self%bound_str), values(1)) + call error%init( & + "value must not be bigger than " // trim(self%bound_str), & + values(1)) return end if store_real_val = real(real_val) @@ -500,7 +510,9 @@ subroutine action_execute(self, args, values, num_values, error) return end if if (str_len > int_bound) then - call error%init("string length must not be bigger than " // trim(self%bound_str), values(1)) + call error%init( & + "string length must not be bigger than " // trim(self%bound_str), & + values(1)) return end if call args%set_string(self%dest, values(1)) diff --git a/src/fclap/fclap_formatter.f90 b/src/fclap/fclap_formatter.f90 index 69b0963..3f1e7f1 100644 --- a/src/fclap/fclap_formatter.f90 +++ b/src/fclap/fclap_formatter.f90 @@ -101,7 +101,8 @@ function format_usage_string(prog, actions, num_actions, & if (.not. first_in_mutex) mutex_str = mutex_str // " | " first_in_mutex = .false. if (actions(m)%num_option_strings > 0) then - mutex_str = mutex_str // trim(actions(m)%option_strings(1)) + mutex_str = mutex_str // & + trim(actions(m)%option_strings(1)) else mutex_str = mutex_str // trim(actions(m)%dest) end if @@ -230,7 +231,8 @@ function format_help_text(prog, description, epilog, actions, num_actions, & do j = 1, num_groups if (groups(j)%num_actions > 0) then - help_text = help_text // new_line('A') // trim(groups(j)%title) // ":" // new_line('A') + help_text = help_text // new_line('A') // trim(groups(j)%title) // & + ":" // new_line('A') if (allocated(groups(j)%description)) then help_text = help_text // " " // groups(j)%description // new_line('A') end if @@ -316,7 +318,8 @@ function format_help_text(prog, description, epilog, actions, num_actions, & if (has_subparsers .and. num_subparsers > 0) then if (present(subparser_title)) then - help_text = help_text // new_line('A') // trim(subparser_title) // ":" // new_line('A') + help_text = help_text // new_line('A') // trim(subparser_title) // & + ":" // new_line('A') else help_text = help_text // new_line('A') // "commands:" // new_line('A') end if diff --git a/src/fclap/fclap_namespace.f90 b/src/fclap/fclap_namespace.f90 index 32cd7da..58084d1 100644 --- a/src/fclap/fclap_namespace.f90 +++ b/src/fclap/fclap_namespace.f90 @@ -1,8 +1,8 @@ !> @file fclap_namespace.f90 !> @brief Namespace module for fclap - stores parsed argument values. !> -!> @details This module defines the Namespace type (similar to Python's -!> argparse.Namespace) which stores the results of parsing command-line +!> @details This module defines the Namespace type (similar to Python's +!> argparse.Namespace) which stores the results of parsing command-line !> arguments. It provides getter methods for retrieving values by key. !> !> The Namespace acts like a dictionary, allowing you to retrieve @@ -13,7 +13,7 @@ !> character(len=256) :: filename !> integer :: count !> logical :: verbose -!> +!> !> args = parser%parse_args() !> call args%get("filename", filename) !> call args%get("count", count, default=1) @@ -522,7 +522,7 @@ end function namespace_get_logical subroutine namespace_get_string_list(self, key, values, count) class(Namespace), intent(in) :: self character(len=*), intent(in) :: key - character(len=*), intent(out) :: values(:) + character(len=MAX_ARG_LEN), intent(out) :: values(:) integer, intent(out) :: count integer :: idx, i @@ -620,7 +620,7 @@ end subroutine namespace_show subroutine namespace_get_sub_string(self, key, value, default) class(Namespace), intent(in) :: self character(len=*), intent(in) :: key - character(len=*), intent(out) :: value + character(len=MAX_ARG_LEN), intent(out) :: value character(len=*), intent(in), optional :: default character(len=:), allocatable :: tmp @@ -682,7 +682,7 @@ end subroutine namespace_get_sub_logical subroutine namespace_get_sub_string_list(self, key, values, count) class(Namespace), intent(in) :: self character(len=*), intent(in) :: key - character(len=*), intent(out) :: values(:) + character(len=MAX_ARG_LEN), intent(out) :: values(:) integer, intent(out) :: count call self%get_string_list(key, values, count) diff --git a/src/fclap/fclap_parser.f90 b/src/fclap/fclap_parser.f90 index 2df00fc..96f1bfe 100644 --- a/src/fclap/fclap_parser.f90 +++ b/src/fclap/fclap_parser.f90 @@ -21,7 +21,12 @@ !> args = parser%parse_args() module fclap_parser - use fclap_constants + use fclap_constants, only: ARG_OPTIONAL, ARG_ZERO_OR_MORE, ARG_ONE_OR_MORE, & + ARG_REMAINDER, ARG_SINGLE, MAX_ARG_LEN, MAX_OPTION_STRINGS, MAX_CHOICES, & + MAX_ACTIONS, MAX_SUBPARSERS, MAX_GROUPS, MAX_GROUP_ACTIONS, MAX_LIST_VALUES, & + TYPE_STRING, TYPE_INTEGER, TYPE_REAL, TYPE_LOGICAL, ACT_STORE, ACT_STORE_TRUE, & + ACT_STORE_FALSE, ACT_COUNT, ACT_APPEND, ACT_HELP, ACT_VERSION, & + ACT_NOT_LESS_THAN, ACT_NOT_BIGGER_THAN, STATUS_ACTIVE, GROUP_STANDARD use fclap_errors, only: fclap_error use fclap_namespace, only: Namespace, ValueContainer use fclap_actions, only: Action, not_less_than, not_bigger_than @@ -255,10 +260,10 @@ function get_prog_name(override) result(prog_name) if (status == 0 .and. length > 0) then allocate(character(len=length) :: arg0) call get_command_argument(0, value=arg0, status=status) - + idx = scan(arg0, '/', back=.true.) if (idx == 0) idx = scan(arg0, '\', back=.true.) - + if (idx > 0) then prog_name = arg0(idx+1:) else @@ -962,9 +967,11 @@ subroutine parser_validate_mutex_groups(self, error) if (j > 1) mutex_names = trim(mutex_names) // " " do k = 1, self%num_actions if (allocated(self%actions(k)%dest)) then - if (trim(self%actions(k)%dest) == trim(self%mutex_groups(i)%action_dests(j))) then + if (trim(self%actions(k)%dest) == & + trim(self%mutex_groups(i)%action_dests(j))) then if (self%actions(k)%num_option_strings > 0) then - mutex_names = trim(mutex_names) // trim(self%actions(k)%option_strings(1)) + mutex_names = trim(mutex_names) // & + trim(self%actions(k)%option_strings(1)) else mutex_names = trim(mutex_names) // trim(self%actions(k)%dest) end if @@ -1116,11 +1123,13 @@ recursive function parser_parse_args_array(self, cmd_args) result(args) do i = 1, num_remaining remaining_args(i) = cmd_args(arg_idx + i - 1) end do - sub_args = self%subparser_parsers(sub_idx)%parse_args_array(remaining_args) + sub_args = self%subparser_parsers(sub_idx)% & + parse_args_array(remaining_args) deallocate(remaining_args) else allocate(remaining_args(0)) - sub_args = self%subparser_parsers(sub_idx)%parse_args_array(remaining_args) + sub_args = self%subparser_parsers(sub_idx)% & + parse_args_array(remaining_args) deallocate(remaining_args) end if ! Merge subparser results into main namespace diff --git a/src/fclap/utils/accuracy.f90 b/src/fclap/utils/accuracy.f90 index 4d9f6b2..a9df6b0 100644 --- a/src/fclap/utils/accuracy.f90 +++ b/src/fclap/utils/accuracy.f90 @@ -25,4 +25,4 @@ module fclap_utils_accuracy integer, parameter :: i8 = selected_int_kind(18) -end module fclap_utils_accuracy \ No newline at end of file +end module fclap_utils_accuracy diff --git a/src/fclap/utils/fclap_version.f90 b/src/fclap/utils/fclap_version.f90 index 97c4d72..a617afd 100644 --- a/src/fclap/utils/fclap_version.f90 +++ b/src/fclap/utils/fclap_version.f90 @@ -58,4 +58,4 @@ subroutine get_fclap_version(major, minor, patch, string) end subroutine get_fclap_version -end module fclap_version \ No newline at end of file +end module fclap_version diff --git a/test/unit/main.f90 b/test/unit/main.f90 index a72a580..f020f84 100644 --- a/test/unit/main.f90 +++ b/test/unit/main.f90 @@ -1,10 +1,10 @@ !> Unit tests for fclap argument parser program tester - use fclap + use fclap, only: ArgumentParser, Namespace, STATUS_DEPRECATED implicit none logical :: all_passed - + all_passed = .true. call test_basic_parsing(all_passed) @@ -348,13 +348,15 @@ subroutine test_mutex_groups(passed) print *, "Test: mutually exclusive groups..." call parser%init(prog="test_prog", add_help=.false.) - + ! Create a mutex group mutex_idx = parser%add_mutually_exclusive_group(required=.false.) - + ! Add mutually exclusive options - call parser%add_argument("--foo", action="store_true", help="Foo option", mutex_group_idx=mutex_idx) - call parser%add_argument("--bar", action="store_true", help="Bar option", mutex_group_idx=mutex_idx) + call parser%add_argument("--foo", action="store_true", help="Foo option", & + mutex_group_idx=mutex_idx) + call parser%add_argument("--bar", action="store_true", help="Bar option", & + mutex_group_idx=mutex_idx) ! Test with only one option (should work) test_args(1) = "--foo" @@ -422,10 +424,10 @@ subroutine test_argument_groups(passed) print *, "Test: argument groups..." call parser%init(prog="test_prog", add_help=.false.) - + ! Create an argument group group_idx = parser%add_argument_group("Input Options", "Options related to input files") - + call parser%add_argument("-i", "--input", help="Input file", group_idx=group_idx) call parser%add_argument("-f", "--format", help="Input format", group_idx=group_idx)