npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

parg.cxx

v1.0.1

Published

A header only c++ library for parsing command line arguments and generating usage/help output; Brett Robinson (2018).

Readme

Parg

A header only c++ library for parsing command line arguments and generating usage/help output, by Brett Robinson.

Features

Parg has the following features:

  • short flags/options
  • long flags/options
  • default values
  • positional arguments
  • [--] arguments
  • piped stdin
  • usage output
  • help output
  • version output
  • helpful parsing error output
  • clean and formatted --help output

Installation

RRun:

$ npm i parg.cxx

And then include parg.hh as follows:

// main.cxx
#include "node_modules/parg.cxx/parg.hh"

int main() { /* ... */ }

And then compile with clang++ or g++ as usual.

$ clang++ main.cxx  # or, use g++
$ g++     main.cxx

You may also use a simpler approach:

// main.cxx
#include <parg.hh>

int main() { /* ... */ }

If you add the path node_modules/parg.cxx to your compiler's include paths.

$ clang++ -I./node_modules/parg.cxx main.cxx  # or, use g++
$ g++     -I./node_modules/parg.cxx main.cxx

Usage

Let's write a program that will accept the flags for help and version info, a string option called file, and an integer option called num.

#include <parg.hh>
#include <string>
#include <iostream>


int main(int argc, char *argv[])
{
  // create the parg object
  OB::Parg pg {argc, argv};

  // set the program name and version
  pg.name("app").version("0.1.0 (00.00.0000)");

  // set a brief description of the program
  pg.description("an example of parg");

  // set the usage info
  pg.usage("[-v|-h]");

  // set the author
  pg.author("octobanana");

  // add help and version flags
  // default value for flags is false
  // flags and options can have either a long and short name, a long name, or a short name.
  // pg.set(<long,short>, <description>);
  // pg.set(<long>, <description>); where long is more than one char
  // pg.set(<short>, <description>); where short is one char
  pg.set("help,h", "print the help output");
  pg.set("version,v", "print the program version");

  // add file option
  // pg.set(<long,short>, <default_value>, <value_description>, <description>);
  pg.set("file,f", "config.cfg", "string", "the file to read from");

  // add num option
  pg.set("num,n", "8", "int", "an integer value");

  // parse the arguments
  // if status > 0, no arguments were found
  // if status = 0, parsing was successful
  // if status < 0, an error occurred while parsing
  int status {pg.parse()};

  if (status < 0)
  {
    // handle parsing error
    std::cout << pg.help() << "\n";
    std::cout << "Error: " << pg.error() << "\n";
    return 1;
  }

  // flags and options are accessed with their long name
  // or short if they don't have a long name
  if (pg.get<bool>("help"))
  {
    // handle -h and --help
    std::cout << pg.help();
    return 0;
  }

  if (pg.get<bool>("version"))
  {
    // handle -v and --version
    std::cout << pg.name() << " v" << pg.version() << "\n";
    return 0;
  }

  // check to see if the file option was found
  // if it wasn't found, the default parameter given will be returned with pg.get("file");
  if (pg.find("file"))
  {
    std::string file {pg.get("file")};
    std::cout << "file: " << file << "\n";
  }
  else
  {
    std::cout << "using default file: " << pg.get("file") << "\n";
  }

  // print out the num value
  int num {pg.get<int>("num")};
  std::cout << "num: " << num << "\n";

  return 0;
}

Running it with the -h flag will output:

app -h
app:
  an example of parg

Usage:
  app [-v|-h]

Flags:
  -h, --help
    print the help output
  -v, --version
    print the program version

Options:
  -f, --file=<string>
    the file to read from
  -n, --num=<int>
    an integer value

Author:
  octobanana

Examples

See the examples directory.

Compile and run each example with:

mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ../
make
./app

SRC

SRC ORG