fclap is a modular Fortran 2018 command-line argument parser inspired by
Python's argparse usage style and partly by Rust's clap regarding features.
It provides typed values, generated help, structured
non-terminating errors, groups, validators, parent parsers, and nested
subcommands.
Command lines use the familiar spellings: --threads=4, -j4, combined
flags such as -vvn, -- to end options, and - as an ordinary value.
Numbers are parsed strictly, integers have 64-bit range, and diagnostics read
like prog: error: argument -j/--threads: value must not be less than 1 (got '0').
--feature/--no-feature flags come from boolean_optional(), and
parser%error("...") reports your own post-parse checks the same way.
The supported application interface is the fclap facade module.
program demo
use fclap, only : ArgumentParser, Namespace, store_true
implicit none
type(ArgumentParser) :: parser
type(Namespace) :: args
call parser%init(prog="demo", description="Process a file")
call parser%add_argument("input", help="input file")
call parser%add_argument("-v", "--verbose", action=store_true(), &
help="enable verbose output")
args = parser%parse_args()
end program demoThree complete example programs demonstrating various capabilities of fclap are available:
example/basic.f90demonstrates the terminating CLI facade, typed retrieval, a flag, a default, and a validator.example/subcommands.f90demonstrates owned child parsers and required subcommands.example/library_mode.f90demonstrates non-terminating parsing and structured failure inspection.
fclap is not packaged for any distribution channel yet; build it from source or add it as an fpm, CMake, or Meson dependency as described below.
To build this project from the source code in this repository you need to have
-
a Fortran compiler supporting Fortran 2018
-
One of the supported build systems
- meson version 0.55 or newer
- CMake version 3.15 or newer
- Fortran package manager (fpm) version 0.2.0 or newer
Get the source by cloning the repository
git clone https://github.com/chselz/fclap
cd fclap
Tests use test-drive. CMake and Meson may resolve that dependency when no installed package is available.
Meson provides the same library and test coverage:
meson setup _build
meson compile -C _build
meson test -C _build --print-errorlogs
meson install -C _buildCMake builds the library, Test Drive suite, and CLI policy fixtures:
cmake -S . -B _build -DCMAKE_BUILD_TYPE=Debug
cmake --build _build
ctest --test-dir _build --output-on-failure
cmake --install _build --prefix /path/to/prefixThe Fortran package manager (fpm) supports the addition of fclap as a dependency.
In the package manifest, fpm.toml, you can add fclap dependency via:
[dependencies]
fclap.git = "https://github.com/chselz/fclap"Then build and test normally.
fpm build
fpm testExamples can be tested with
fpm run --example basic -- input.dat --threads 2 --verboseStart with the tutorial; every public procedure is described in the API reference. Maintainers should read ARCHITECTURE.md first.
Build the Sphinx documentation locally with:
python -m pip install -r doc/requirements.txt
sphinx-build -W -b html doc/source doc/build/htmlThis is a volunteer open source project and contributions are always welcome. Please, take a moment to read the contributing guidelines on how to get involved in fclap.
fclap is free software: you can redistribute it and/or modify it under the terms of the MIT license.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an as is basis, without warranties or conditions of any kind, either express or implied. See the License for the specific language governing permissions and limitations under the License.