All Projects → pfultz2 → args

pfultz2 / args

Licence: other
Simple and type-safe commandline argument parser for C++14

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to args

declarative-parser
Modern, declarative argument parser for Python 3.6+
Stars: ✭ 31 (-50.79%)
Mutual labels:  argument-parser, command-line-parser
Argagg
A simple C++11 command line argument parser
Stars: ✭ 180 (+185.71%)
Mutual labels:  argument-parser, command-line-parser
dropt
dropt is yet another C library for parsing command-line options.
Stars: ✭ 39 (-38.1%)
Mutual labels:  argument-parser, command-line-parser
argparser
Simple command-line parser for C/C++ programs
Stars: ✭ 50 (-20.63%)
Mutual labels:  argument-parser, command-line-parser
Clap
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
Stars: ✭ 7,174 (+11287.3%)
Mutual labels:  argument-parser, command-line-parser
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+2531.75%)
Mutual labels:  argument-parser, command-line-parser
minimist2
TypeScript/JavaScript ES6 rewrite of popular Minimist argument parser
Stars: ✭ 20 (-68.25%)
Mutual labels:  argument-parser, command-line-parser
CmdLine2
Command line argument parser (C++14)
Stars: ✭ 18 (-71.43%)
Mutual labels:  argument-parser, command-line-parser
Kotlin Argparser
Easy to use and concise yet powerful and robust command line argument parsing for Kotlin
Stars: ✭ 431 (+584.13%)
Mutual labels:  argument-parser, command-line-parser
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+5104.76%)
Mutual labels:  argument-parser, command-line-parser
option-parser
A Lightweight, header-only CLI option parser for C++
Stars: ✭ 16 (-74.6%)
Mutual labels:  argument-parser, command-line-parser
Argumentparser
Faster, easier, more declarative parsing of command line arguments in Objective-C/Foundation.
Stars: ✭ 251 (+298.41%)
Mutual labels:  argument-parser, command-line-parser
Argparse
Argparse for golang. Just because `flag` sucks
Stars: ✭ 294 (+366.67%)
Mutual labels:  argument-parser, command-line-parser
Argh
Argh! A minimalist argument handler.
Stars: ✭ 752 (+1093.65%)
Mutual labels:  argument-parser, command-line-parser
Programoptions.hxx
Single-header program options parsing library for C++11
Stars: ✭ 112 (+77.78%)
Mutual labels:  argument-parser, command-line-parser
Optimus
Command line arguments parser for Elixir
Stars: ✭ 110 (+74.6%)
Mutual labels:  argument-parser
Commanddotnet
A modern framework for building modern CLI apps
Stars: ✭ 251 (+298.41%)
Mutual labels:  argument-parser
Sywac
🚫 🐭 Asynchronous, single package CLI framework for Node
Stars: ✭ 109 (+73.02%)
Mutual labels:  argument-parser
command-line-commands
Add a git-like command interface to your app.
Stars: ✭ 40 (-36.51%)
Mutual labels:  command-line-parser
Lyra
A simple to use, composable, command line parser for C++ 11 and beyond
Stars: ✭ 238 (+277.78%)
Mutual labels:  argument-parser

Args

Simple and typesafe commandline parsing for C++14.

Quickstart

Simply provide a class with fields that is to be filled by command-line arguments:

struct hello
{
    static const char* help()
    {
        return "Simple program that greets NAME for a total of COUNT times.";
    }
    int count;
    std::string name;

    hello() : count(1)
    {}

    template<class F>
    void parse(F f)
    {
        f(count, "--count", "-C", args::help("Number of greetings."));
        f(name, "--name", "-N", args::help("The person to greet."), args::required());
    }

    void run()
    {
        for(int i=0;i<count;i++) printf("%s\n", name.c_str());
    }
};

int main(int argc, char const *argv[]) 
{
    args::parse<hello>(argc, argv);
}

The command then could be run like this:

$ hello --name Paul --count 3
Paul
Paul
Paul

The args library will auto-generate help info:

$ hello --help
Usage: hello [options...]

  Simple program that greets NAME for a total of COUNT times.  

Options: 

            -h, --help Show help  
 --count, -C [integer] Number of greetings.  
   --name, -N [string] The person to greet.

In addition, nested commands can be created:

struct cli : args::group<cli>
{
    static const char* help()
    {
        return "Command-line interface to manage a database";
    }
};

struct initdb : cli::command<initdb>
{
    initdb() {}
    static const char* help()
    {
        return "Initialize database";
    }
    void run()
    {
        printf("Initialize database\n");
    }
};

struct dropdb : cli::command<dropdb>
{
    dropdb() {}
    static const char* help()
    {
        return "Delete database";
    }
    void run()
    {
        printf("Delete database\n");
    }
};

int main(int argc, char const *argv[]) 
{
    args::parse<cli>(argc, argv);
}

So each subcommand can be ran like this:

$ cli initdb
Initialize database
$ cli dropdb
Delete database

In addition help is generated for subcommands as well:

$ cli --help
Usage: cli [options...] [command]

  Command-line interface to manage a database  

Options: 

 -h, --help Show help  

Commands: 

     dropdb Delete database  
     initdb Initialize database  

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].