Advanced getopt for C++ projects

Introduction

This project is an advanced getopt() class to use with your C++ projects. It handles most everything that GNU-like tools offer as far as command line options go.

The main idea is for you to have as little to do as possible parsing your command line arguments and configuration files. The library expects a table of available options with a short and long version of the options, and whether they accept arguments (i.e. -f <filename>).

In your C++ program you can then just check whether a parameter is defined or not with the is_defined() function and get the value as a string, an integer, etc. as required by your tool. Data verification is done automatically for basic types such as integers.

Download

The source is available on github in our project git.

On Ubuntu, you may want to install it from our Snap! C++ Launchpad PPA. In that case, add the repository this way:

sudo add-apt-repository ppa:snapcpp/ppa
sudo apt-get update

Then install one of the library packages with the install command:

sudo apt-get install libadvgetopt
sudo apt-get install libadvgetopt-dev
sudo apt-get install libadvgetopt-doc

List of currently available Snap! C++ packages.

Support

You got a problem with the library? An idea to improve it? Please post a ticket in the Support area of SourceForget.net.

Note: we have a couple of internal issues in our Jira about advgetopt project: (1) we want to have support for all the configuration capabilities as found in libsnapwebsites (snap_config.cpp/h) and (2) we'd like to allow for logging capabilities. Specifically, we do not want to print errors directly in stderr because this library is used by many daemons and we'd miss those errors unless written to our logs.

Requirements

We use cmake to compile the library from source. Other than that the only requirements are standard libraries. As it stands, though, it probably needs the snap cmake modules even if it doesn't really use them.

Documentation

The libadvgetopt-doc package includes all the documentation on how to use the library.

The different snapwebsites tools (under snapwebsites/<project-name>/src) will give you extensive examples on how the library gets used.

Coverage Tests

The library comes with a unit test which attempts to keep the coverage as close as possible to 100%. The test results can be found on lcov.snapwebsites.org/advgetopt.

Origin

This library was originally developed for wpkg.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly