Declare a flag, which takes no value.
An absent flag reads back as "false", a present one as "true", so
get into a logical works without a special case.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name, given on the command line as |
||
| character(len=*), | intent(in) | :: | help |
One-line description. |
||
| character(len=*), | intent(in), | optional | :: | short |
Single-character short name. |
subroutine cli_add_flag(this, name, help, short) !! Declare a flag, which takes no value. !! !! An absent flag reads back as `"false"`, a present one as `"true"`, so !! `get` into a `logical` works without a special case. class(cli_t), intent(inout) :: this character(len=*), intent(in) :: name !! Long name, given on the command line as `--name`. character(len=*), intent(in) :: help !! One-line description. character(len=*), intent(in), optional :: short !! Single-character short name. call this%reserve() this%count = this%count + 1_default_int this%entries(this%count)%name = name this%entries(this%count)%help = help this%entries(this%count)%kind = KIND_FLAG this%entries(this%count)%required = .false. this%entries(this%count)%seen = 0_default_int this%entries(this%count)%value = "false" this%entries(this%count)%default = "false" if (present(short)) then this%entries(this%count)%short = short else this%entries(this%count)%short = "" end if end subroutine cli_add_flag