Skip to content

Memphizzz/simpleparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simpleparser

SimpleParser - parsing command line arguments made simple.
Just parse no sets etc. (maybe in the future)
Simple: b -b --bool does work for bool arguments as well as f <filename> -f <filename> --file <fileName> works for parameters.
For multiple strings use the ListOption attribute which will return a List<string> for Separator-separated strings. Default: comma separated.

Option attributes:


[Option("ShortName", "LongName", "DefaultValue")]
Main attribute for returning parameters after ShortName or LongName. Optionally specify a default value.

[BoolOption("ShortName", "Index")
Returns true/false if ShortName exists. Optionally you can specify an Index in args[] to meet.

[IndexOption(Index)]
Returns args[Index].

[ListOption('Separator')]
Special Option for List<string> properties.

Usage:


Simply create a class called Options for example and set its properties attributes like this:

    class Options
    {
        [BoolOption("v", "verbose")]
        public bool Verbose { get; set; }

        [Option("o", "outdir")]
        public string OutputDir { get; set; }

        [ListOption("f", "files")]
        public List<string> Files { get; set; }

        [IndexOption(0)]
        public string First { get; set; }
    }

Now in your code run:

Options options = new Options();
X_ToolZ.SimpleParser.Parse(args, options);

and your options instance's properties should be populated.

Have fun!

Contact me:


MemphiZ AT X-ToolZ DOT com
Web: X-ToolZ.com (under construction)
Twitter: @XToolZ

About

parsing command line arguments made simple.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages