Fortran command Line Arguments Parser for poor people — a pure Fortran 2003+ library for building elegant CLIs, inspired by Python's argparse.
- Optional, required, boolean, positional, and list-valued arguments
nargssupport: fixed count ('3'), one-or-more ('+'), zero-or-more ('*')- Mutually exclusive arguments and command groups
- Nested subcommands
- Environment variable and fake-input support
- Automatic help, usage, man page, bash completion, and Markdown generation
- POSIX compliant
- Stefano Zaghi — @szaghi
Contributions are welcome — see the Contributing page.
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to this project is welcome — pick the license that best fits your needs.
A minimal plate:
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 minimalRunning without arguments prints an automatic help message:
./minimal: error: named option "--string" is required!
usage: ./minimal --string value [--help] [--version]
minimal FLAP example
Required switches:
--string value, -s value
a string
See src/tests/ for more examples including nested subcommands, mutually exclusive groups, choices, and bash completion.
Add to your fpm.toml:
[dependencies]
FLAP = { git = "https://github.com/szaghi/FLAP.git" }Then build and test:
fpm build
fpm testgit clone https://github.com/szaghi/FLAP
cd FLAP
git submodule update --init| Tool | Command |
|---|---|
| FPM | fpm build --profile release |
| FoBiS.py | FoBiS.py build -mode static-gnu |
| GNU Make | make |
| CMake | cmake -B build && cmake --build build |
NVFortran note: pass
-Mbackslashto work around backslash-in-string handling, e.g.cmake -D CMAKE_Fortran_FLAGS="-Mbackslash" ...