Giter Site home page Giter Site logo

argpp's Introduction

Arg++


A nice and clean C++ class for handling the work of parsing input arguments.
Sorts the arguments correctly and binds them together with flags.
This allows the programmer to quickly identify and implement different command-line input.
At the same time; all dirty code is abstracted away.

Command Line Conventions


Maybe this'll be useful if you're not very known with command-line commands.
http://publib.boulder.ibm.com/tividd/td/tec/SC32-1232-00/en_US/HTML/ecormst15.htm

Tiny Tutorial


We read the argument string from left to right.

Path


The path that the program is being run from is always fetched and stored separately.
It is returned by the "getPath()" method, and is always the first string of char *argv[].

Flag


A flag is a program option. Options are defined by:

    • one dash; single-character option
  • -- two dashes; multiple-character option

Argument


An argument is a piece of data that belongs to a flag.
Method 1: "-o a" would make "a" the argument to option "-o". This method uses a whitespace as separator.
Method 2: "-o=a" would make "a" the argument to option "-o". This method uses a '=' as separator.
An argument will always be bound to the last unset, non-inert flag.
(We get back to that later)

Flag Chaining


A single-characted flag can be chained:
"-a -b -c" becomes "-abc"

Option-Argument Mirroring


Arguments will be applied to the last unset, non-inert flag such that in:
"-q -abc uvw dre xyz nmr"
uvw will be bound to "-c"
dre will be bound to "-b"
xyz will be bound to "-a"
and nmr will be bound to "-q"

Inertia


Flags that are inert will not be filled in by arguments:
Let flags "-a", "-b", "-c" exist.
Let flag "-b" be inert.
"-abc some argument"
Will bind "some" to "-c" and "argument" to "-a".

Operands


Operands are flagless arguments. They are created when:

  1. There are no more flags to bind to
    or
  2. We have given anything behind "--" (Flag Terminator)
  3. Operands are sorted by order and can be retrieved using getOperand(std::size_t).
  4. getOperandCount() returns the amount of operands. getOperand does not check bounds.

Flag Termination


All flag-starters ('-' and "--") will be ignored after issueing a "--" followed by nothing:
Let flags "-a", "-b", "-c" exist.
Let flag "-b" be inert.
"-ab data -- -c dr"
Will bind "data" to "-a"
Will add "-c" and "dr" to a collection of operands.

About


C++ argument parsing utility class.
Written in pure C++.
Conforms with the GNU Utility Syntax guidelines. One exception: "-o foo" is NOT "-ofoo" due to "option-argument mirroring".
More info: http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

Sample


See the folder ./src/main.cpp
This file will contain a complete test

argpp's People

Contributors

kstrafe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.