All Projects → fenekku → commandeer

fenekku / commandeer

Licence: MIT License
Take command of your command line in Nim

Programming Languages

nim
578 projects

Projects that are alternatives of or similar to commandeer

cmdr
POSIX-compliant command-line UI (CLI) parser and Hierarchical-configuration operations
Stars: ✭ 94 (+11.9%)
Mutual labels:  commandline, command-line-parser
Utility.CommandLine.Arguments
A C# .NET class library containing tools for parsing the command line arguments of console applications.
Stars: ✭ 105 (+25%)
Mutual labels:  commandline, command-line-parser
CommandLineParser.Core
💻 A simple, light-weight and strongly typed Command Line Parser made in .NET Standard!
Stars: ✭ 32 (-61.9%)
Mutual labels:  commandline, command-line-parser
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+3811.9%)
Mutual labels:  commandline, command-line-parser
prettyBenching
🦕 A small lib to make your Deno benchmarking progress and results look pretty
Stars: ✭ 23 (-72.62%)
Mutual labels:  commandline
DfmExtractor
Small command line utility which allows you to extract DFM, LFM and FRM forms from executable files compiled by Delphi, Lazarus and CodeTyphon.
Stars: ✭ 22 (-73.81%)
Mutual labels:  commandline
console-logging
Better, prettier commandline logging for Python--with colors! 👻
Stars: ✭ 111 (+32.14%)
Mutual labels:  commandline
declarative-parser
Modern, declarative argument parser for Python 3.6+
Stars: ✭ 31 (-63.1%)
Mutual labels:  command-line-parser
git-admin
A package to help manage git repositories through the commandline
Stars: ✭ 27 (-67.86%)
Mutual labels:  commandline
tiles
Commandline tool that makes building tilesets and rendering static tilemaps super easy!
Stars: ✭ 51 (-39.29%)
Mutual labels:  commandline
vt100
💻 VT100 Terminal Package
Stars: ✭ 19 (-77.38%)
Mutual labels:  commandline
Commandline-Games-hacktoberfest
A repository to share command line games. An opportunity to start and learn about open source code contributions flow.
Stars: ✭ 16 (-80.95%)
Mutual labels:  commandline
cotp
Trustworthy, encrypted, command-line TOTP/HOTP authenticator app with import functionality.
Stars: ✭ 45 (-46.43%)
Mutual labels:  commandline
dropt
dropt is yet another C library for parsing command-line options.
Stars: ✭ 39 (-53.57%)
Mutual labels:  command-line-parser
Data-Scientist-In-Python
This repository contains notes and projects of Data scientist track from dataquest course work.
Stars: ✭ 23 (-72.62%)
Mutual labels:  commandline
ansiart2utf8
Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8. Escape codes and line endings are processed for terminal friendliness.
Stars: ✭ 32 (-61.9%)
Mutual labels:  commandline
discord-message-handler
Message and command handler for discord.js bots and applications
Stars: ✭ 19 (-77.38%)
Mutual labels:  command-line-parser
select-run
A CLI tool to interactively search & select one or many package.json npm scripts to run
Stars: ✭ 29 (-65.48%)
Mutual labels:  commandline
note-keeper
📓 A tiny bash tool for taking and organizing notes.
Stars: ✭ 58 (-30.95%)
Mutual labels:  commandline
option-parser
A Lightweight, header-only CLI option parser for C++
Stars: ✭ 16 (-80.95%)
Mutual labels:  command-line-parser

Commandeer

Build Status

Take command of your command line.

Commandeer gets data from the command line to your variables and exits gracefully if there is any issue.

It does this little thing well and lets you deal with the rest.

Usage

In code

## myCLApp.nim

import commandeer

commandline:
  argument integer, int
  argument floatingPoint, float
  argument character, char
  arguments strings, string
  option optionalInteger, int, "int", "i", -1
  option testing, bool, "testing", "t"
  exitoption "help", "h",
             "Usage: myCLApp [--testing|--int=<int>|--help] " &
             "<int> <float> <char> <string>..."
  errormsg "You made a mistake!"

echo("integer = ", integer)
echo("floatingPoint = ", floatingPoint)
echo("character = ", character)
echo("strings (one or more) = ", strings)

if optionalInteger != 0:
  echo("optionalInteger = ", optionalInteger)

if testing:
  echo("Testing enabled")

On the command line

$ myCLApp --testing 4 8.0 a one two -i:100
integer = 4
floatingPoint = 8.0
character = a
strings (one or more) = @[one, two]
optionalInteger = 100
Testing enabled
$ myCLApp 10 --help
Usage: myCLApp [--testing|--int=<int>|--help] <int> <float> <char> <string>...

When you have commandeer installed, try passing an incorrect set of command line arguments for fun!

See the tests folder for other examples.

It doesn't seek to do too much; it just does what's needed.

Installation

There are 2 ways to install commandeer:

nimble

Install nimble. Then do:

$ nimble install commandeer

This will install the latest tagged version of commandeer.

raw

Copy the commandeer.nim file to your project and import it.

When I go this way for Nim libraries, I like to create a libs/ folder in my project and put third-party files in it. I then add the line path = "libs" to my nim.cfg file so that the libs/ directory is looked into at compile time.

Documentation

commandline

commandline is used to delimit the space where you define the command line arguments and options you expect. All other commandeer constructs (described below) are placed under it. They are all optional - although you probably want to use at least one, right?

subcommand identifier, name[, alias1, alias2...]

subcommand declares identifier to be a variable of type bool that is true if the first command line argument passed is name or one of the aliases (alias1, alias2, etc.) and is false otherwise. Under it, you define the subcommand arguments and options you expect. All other commandeer constructs (described below) can be placed under it.

For example:

commandline:
  subcommand add, "add", "a":
    arguments filenames, string
    option force, bool, "force", "f"
  option globalOption, bool, "global", "g"

if add:
  echo "Adding", filenames
if globalOption:
  echo "Global option activated"

See tests/testSubcommands.nim for a larger example.

argument identifier, type

argument declares a variable named identifier of type type initialized with the value of the corresponding command line argument converted to type type.

Correspondence works as follows: the first occurrence of argument corresponds to the first argument, the second to the second argument and so on. Note that if a subcommand is declared then 1) any top-level occurrence of argument is ignored, 2) the first subcommand argument corresponds to the first command line argument after the subcommand, the second to the second argument after the subcommand and so on.

arguments identifier, type [, atLeast1]

arguments declares a variable named identifier of type seq[type] initialized with the value of the sequential command line arguments that can be converted to type type. By default atLeast1 is true which means there must be at least one argument of type type or else an error is thrown. Passing false there allows for 0 or more arguments of the same type to be stored at identifier.

Warning: arguments myListOfStrings, string will eat all arguments on the command line. The same applies to other situations where one type is a supertype of another type in terms of conversion e.g., floats eat ints.

option identifier, type, long name, short name [, default]

option declares a variable named identifier of type type initialized with the value of the corresponding command line option --long name or -short name converted to type type if it is present. The -- and - are added by commandeer for your convenience. If the option is not present, identifier is initialized to its default type value or the passed default value.

The command line option syntax follows Nim's one and adds space (!) i.e., --times=3, --times:3, -t=3, -t:3, --times 3 and -t 3 are all valid.

Syntactic sugar is provided for boolean options such that only the presence of the option is needed to give a true value.

exitoption long name, short name, exit message

exitoption declares a long and short option string for which the application will immediately output exit message and exit. This can be used for subcommand specific exit messages too:

commandline:
  subcommand add, "add":
    arguments filenames, string
    exitoption "help", "h", "add help"
  exitoption "help", "h", "general help"

This is mostly used for printing the version or the help message.

errormsg custom error message

errormsg sets a string custom error message that will be displayed after the other error messages if the command line arguments or options are invalid.

Valid types for type are:

  • int, float, string, bool, char

Design

  • Keep as much logic out of the module and into the hands of the developer as possible
  • No magical variables should be made implicitly available. All created variables should be explicitly chosen by the developer.
  • Keep it simple and streamlined. Command line parsers can do a lot for you, but I prefer to be in adequate control.
  • Test in context. Tests are run on the installed package because that is what people get.

Tests

Run the test suite:

nimble tests

TODO and Contribution

  • Use and see what needs to be added
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].