FLAP

March 2, 2026 ยท View on GitHub

Fortran command Line Arguments Parser for poor people

a pure Fortran 2003+ library for building elegant CLIs, inspired by Python's argparse.

GitHub tag GitHub issues CI coverage License

๐Ÿ“‹ Argument Types
Optional, required, boolean, positional, list-valued, and env-var-bound arguments
๐Ÿ”ข nargs Support
Fixed count ('3'), one-or-more ('+'), zero-or-more ('*')
๐Ÿ”€ Groups & Subcommands
Mutually exclusive argument groups and arbitrarily nested subcommands
๐Ÿ“„ Auto-generated Output
Help, usage, man page, bash completion, and Markdown โ€” all automatic
๐Ÿ argparse-inspired
Familiar Python-like API brought to modern Fortran
โœ… POSIX compliant
Standard CLI conventions respected out of the box
๐Ÿ”“ Multi-licensed
GPL v3 ยท BSD 2/3-Clause ยท MIT
๐Ÿ“ฆ Multiple build systems
fpm, FoBiS, CMake, Make

Documentation

For full documentation (guide, API reference, examples, etc...) see the FLAP website.


Authors

Contributions are welcome โ€” see the Contributing page.

Copyrights

This project is distributed under a multi-licensing system:

Anyone interested in using, developing, or contributing to this project is welcome โ€” pick the license that best fits your needs.


Quick start

program minimal
  use flap
  implicit none
  type(command_line_interface) :: cli
  character(99) :: string
  integer       :: error

  call cli%init(description='minimal FLAP example')
  call cli%add(switch='--string', switch_ab='-s', help='a string', &
               required=.true., act='store', error=error)
  if (error /= 0) stop
  call cli%parse(error=error)
  if (error /= 0) stop
  call cli%get(switch='-s', val=string, error=error)
  if (error /= 0) stop

  print '(A)', 'String = ' // trim(string)
end program minimal

See src/tests/ for more examples including nested subcommands, mutually exclusive groups, choices, and bash completion.


Install

FoBiS

Standalone โ€” clone, fetch dependencies, and build:

git clone https://github.com/szaghi/FLAP && cd FLAP
FoBiS.py fetch                        # fetch PENF, FACE
FoBiS.py build -mode static-gnu       # build static library

As a project dependency โ€” declare FLAP in your fobos and run fetch:

[dependencies]
deps_dir = src/third_party
FLAP = https://github.com/szaghi/FLAP
FoBiS.py fetch           # fetch and build
FoBiS.py fetch --update  # re-fetch and rebuild

fpm

Add to your fpm.toml:

[dependencies]
FLAP = { git = "https://github.com/szaghi/FLAP" }
fpm build
fpm test

CMake

cmake -B build && cmake --build build

GNU Make

make