GithubHelp home page GithubHelp logo

flagrant's Introduction

๐Ÿ Flagrant

Build Status

A little flag parsing tool for .Net

How to use

  1. Add a reference to Flagrant project or build the project then add a reference to the Flagrant.dll from your own project.

  2. Create a new instance of Flagrant by giving the static method Parse an array of strings.

  3. Tell flagrant which flags you want to extract by providing three parameters:

  • Flagname - Name of the flag in the given dictionary.
  • DefaultValue - Default value that will be used, if the flat wasn't found in the dictionary.
  • Value - References the variable where the retrieved value will be stored.
public static void Main(string[] args)
{
  Flagrant.Parse(args)
    .String("name", "Phillip", out var name)
    .Int("age", 24, out var age);

  Console.WriteLine($"Hey {name}, only {10%age} years to the big day!");
}

Types of flags

You can use the following methods to extract the flags with different types:

  • .String(string flagname, string defaultValue, out string value)
  • .Int(string flagname, int defaultValue, out int value)
  • .Long(string flagname, long defaultValue, out long value)
  • .Float(string flagname, float defaultValue, out float value)
  • .Double(string flagname, double defaultValue, out double value)
  • .Bool(string flagname, bool defaultValue, out var value)
  • .Enum<TEnum>(string flagename, TEnum defaultValue, out TEnum value)
  • .Custom<T>(string flagename, T defaultValue, Func<string, T> func, out T value)

Custom Flags

With the Custom method, it's possible to convert arguments into custom types. The additional Func parameter is responsible for converting the string representation into it's corresponding custom value.

Flagrant Project Directory

Flagrant
โ”œโ”€โ”€ Flagrant.cs
โ”œโ”€โ”€ Flagrant.csproj

flagrant's People

Contributors

chrsi avatar praffn avatar muhihsan avatar

Watchers

James Cloos avatar  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.