All Projects → sailormoon → Flags

sailormoon / Flags

Licence: unlicense
⛳ Simple, extensible, header-only C++17 argument parser released into the public domain.

Projects that are alternatives of or similar to Flags

Pi Hole Pivpn On Google Compute Engine Free Tier With Full Tunnel And Split Tunnel Openvpn Configs
Run your own privacy-first ad blocking service in the cloud for free on Google Cloud Services.
Stars: ✭ 1,141 (+510.16%)
Mutual labels:  free, free-software
Gophie
An Aggregator Engine for searching and downloading movies free - NO ADs!
Stars: ✭ 94 (-49.73%)
Mutual labels:  free, free-software
Rboxlo
Roblox private server
Stars: ✭ 69 (-63.1%)
Mutual labels:  free, public-domain
Cortex
Cortex: a Powerful Observable Analysis and Active Response Engine
Stars: ✭ 676 (+261.5%)
Mutual labels:  free, free-software
Thehive4py
Python API Client for TheHive
Stars: ✭ 143 (-23.53%)
Mutual labels:  free, free-software
Awesome Startup
😎 All the required resources to build your own startup
Stars: ✭ 702 (+275.4%)
Mutual labels:  free, free-software
Libmacgpg Free
A drop-in replacement for GPGTools libmacgpg that disables the paywall (free MacGPG)
Stars: ✭ 175 (-6.42%)
Mutual labels:  free, free-software
cmd-ts
💻 A type-driven command line argument parser
Stars: ✭ 92 (-50.8%)
Mutual labels:  parse, argument-parser
Web Presentation
Jekyll theme template to create web presentation
Stars: ✭ 137 (-26.74%)
Mutual labels:  free, simple
Im ios
GoBelieveIO IM iOS sdk
Stars: ✭ 116 (-37.97%)
Mutual labels:  free, free-software
Thehivedocs
Documentation of TheHive
Stars: ✭ 353 (+88.77%)
Mutual labels:  free, free-software
Imaginary Teleprompter
Professional grade, free software, teleprompter app.
Stars: ✭ 157 (-16.04%)
Mutual labels:  free, free-software
Awesome Free Services
Awesome free online services for startups and freelancers!
Stars: ✭ 269 (+43.85%)
Mutual labels:  free, free-software
Server Manager
This repository holds the IntISP Interface. It can be rebuilt to interface with any other hosting panel.
Stars: ✭ 31 (-83.42%)
Mutual labels:  free, simple
mr-brown
Mr.Brown is a responsive Jekyll theme
Stars: ✭ 21 (-88.77%)
Mutual labels:  simple, free
Uebergame
Uebergame code repository
Stars: ✭ 90 (-51.87%)
Mutual labels:  free, free-software
Rboxlo
Roblox private server
Stars: ✭ 173 (-7.49%)
Mutual labels:  public-domain, free
add-to-calendar-button
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
Stars: ✭ 697 (+272.73%)
Mutual labels:  simple, free
Avideo
Create Your Own Broadcast Network With AVideo Platform Open-Source. OAVP OVP
Stars: ✭ 1,329 (+610.7%)
Mutual labels:  free, free-software
Hippocampe
Threat Feed Aggregation, Made Easy
Stars: ✭ 149 (-20.32%)
Mutual labels:  free, free-software

⛳ flags

Build Status

Simple, extensible, header-only C++17 argument parser released into the public domain.

why

Other argument parsers are:

  • bloated
  • non-extensible
  • not modern
  • complicated

requirements

GCC 7.0 or Clang 4.0.0 at a minimum. This library makes extensive use of optional, nullopt, and string_view.

api

flags::args exposes three methods:

get

std::optional<T> get(const std::string_view& key) const

Attempts to parse the given key on the command-line. If the string is malformed or the argument was not passed, returns nullopt. Otherwise, returns the parsed type as an optional.

get (with default value)

T get(const std::string_view& key, T&& default_value) const

Functions the same as get, except if the value is malformed or the key was not provided, returns default_value. Otherwise, returns the parsed type.

positional

const std::vector<std::string_view>& positional() const

Returns all of the positional arguments from argv in order.

usage

Just include flags.h from the include directory into your project.

example

#include "flags.h"
#include <iostream>

int main(int argc, char** argv) {
  const flags::args args(argc, argv);

  const auto count = args.get<int>("count");
  if (!count) {
    std::cerr << "No count supplied. :(\n";
    return 1;
  }
  std::cout << "That's " << *count << " incredible, colossal credits!\n";

  if (args.get<bool>("laugh", false)) {
    std::cout << "Ha ha ha ha!\n";
  }
  return 0;
}
$ ./program
> No count supplied. :(
$ ./program --count=5 --laugh
> That's 5 incredible, colossal credits!
> Ha ha ha ha!

another example

#include "flags.h"
#include <iostream>
#include <string>

int main(int argc, char** argv) {
  const flags::args args(argc, argv);
  const auto& files = args.positional();
  const auto verbose = args.get<bool>("verbose", false);
  if (verbose) {
    std::cout << "I'm a verbose program! I'll be reading the following files:\n";
    for (const auto& file : files) {
      std::cout << "* " << file << '\n';
    }
  }
  // read files(files);
  return 0;
}
$ ./program /tmp/one /tmp/two /tmp/three --verbose
> I'm a verbose program! I'll be reading the following files: 
> * /tmp/one
> * /tmp/two
> * /tmp/three
$ ./program /tmp/one /tmp/two /tmp/three --noverbose
>%

extensions

flags simply uses the istream operator to parse values from argv. To extend the parser to support your own types, just supply an overloaded >>.

example

struct Date {
  int day;
  int month;
  int year;
};

// Custom parsing code.
std::istream& operator>>(std::istream& stream, Date& date) {
  return stream >> date.day >> date.month >> date.year;
}

int main(int argc, char** argv) {
  const flags::args args(argc, argv);
  if (const auto date = args.get<Date>("date")) {
    // Output %Y/%m/%d if a date was provided.
    std::cout << date->year << ":" << date->month << ":" << date->day << '\n';
    return 0;
  }
  // Sad face if no date was provided or if the input was malformed.
  std::cerr << ":(\n";
  return 1;
}
$ ./program --date="10 11 2016"
> 2016:11:10
$ ./program
> :(

command line details

flags's primary goal is to be simple to use for both the user and programmer.

key formatting

A key can have any number of preceding -s, but must have more than 0. The following are valid keys:

  • -key
  • --key
  • -------------key

value assignment

A value can be assigned to a key in one of two ways:

  • $ ./program --key=value
  • $ ./program --key value

bools

booleans are a special case. The following values make an argument considered false-y when parsed as a bool:

  • f
  • false
  • n
  • no
  • 0

If none of these conditions are met, the bool is considered true.

testing

flags uses both bfg9000 and mettle for unit-testing. After installing both bfg9000 and mettle, run the following commands to kick off the tests:

  1. 9k build/
  2. cd build
  3. ninja test

contributing

Contributions of any variety are greatly appreciated. All code is passed through clang-format using the Google style.

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].