Skip to content

oliverdelancey/clapfn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clapfn

Language Nimble License

clapfn is an easy-to-use Command Line Argument Parser For Nim.

Please contact me if you have any issues using this library. This library is actively maintained and supported; I haven't made any commits lately simply because this project seems to be stable. But feel free to contact me via an issue, and I will see what I can do!

Installation

Installing is as simple as:

nimble install clapfn

Usage

clapfn is specifically designed to be straightforward to work with.

import tables
import clapfn

var parser = ArgumentParser(programName: "mcp", fullName: "My Cool Program",
                            description: "A test program.", version: "0.0.0",
                            author: "An Author <[email protected]>")

# See the wiki for in-depth documentation, especially the purposes
# of the various parameters.

# It is not necessary to use the argument names; they are here
# simply for explanation. *All* function arguments are required.
parser.addRequiredArgument(name="in_file", help="Input file.")
parser.addStoreArgument(shortName="-o", longName="--out", usageInput="output",
                        default="out.file", help="Specify the output file.")
parser.addSwitchArgument(shortName="-d", longName="--debug", default=false,
                         help="Enable debug printing.")

let args = parser.parse()

echo args["in_file"]
echo args["out"]
echo args["debug"]

And if you were to run mcp --help:

My Cool Program v0.0.0
An Author <[email protected]>
A test program.

Usage: mcp [-h] [-v] [-o output] [-d] in_file

Required arguments:
    in_file                  Input file.

Optional arguments:
    -h, --help               Show this help message and exit.
    -v, --version            Show version number and exit.
    -o=output, --out=output  Specify the output file.
    -d, --debug              Enable debug printing.

clapfn uses Nim's default delimiter style:

# good
-o:output
-o=output

# BAD
-o output

The values of the command line arguments are stored in a Table, and can be accessed thus:

args["in_file"]
args["out"]
args["debug"]
# etc

See example.nim for a fully functional example.

Documentation

See the wiki for documentation.

License

This project uses the MIT License

Contact

Raise an Issue! I'll see you there.

Project link: https://github.com/oliverdelancey/clapfn

About

A fast and simple command line argument parser for Nim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages