Skip to content

szaghi/FLAP

Repository files navigation

FLAP

Fortran command Line Arguments Parser for poor people — a pure Fortran 2003+ library for building elegant CLIs, inspired by Python's argparse.

CI Coverage GitHub tag License


Features

  • Optional, required, boolean, positional, and list-valued arguments
  • nargs support: 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

Documentation | API Reference


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

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 minimal

Running 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.


Install

FPM (recommended)

Add to your fpm.toml:

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

Then build and test:

fpm build
fpm test

Clone and build

git 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 -Mbackslash to work around backslash-in-string handling, e.g. cmake -D CMAKE_Fortran_FLAGS="-Mbackslash" ...