#arguments #flags #helper #statement #value #command #convert

easy_argv

Provides a helper for pulling and converting arguments, flags, and value overrides from a command statement

2 releases

0.1.2 Apr 29, 2024
0.1.0 Apr 29, 2024

#541 in Algorithms

Download history 253/week @ 2024-04-26 33/week @ 2024-05-03

286 downloads per month

MIT license

18KB
294 lines

Easy Argv

Purpose

Easy Argv is a helper library for interpreting command line input, whether from the shell or in an interactive console application.
It has the ability to automatically convert arguments to a target data type using either the FromStr trait or a helper object if more information that just the string itself is required to transform the string into the desired type.

Usage

Instantiation

Usage of the library is primarily through the ArgVector struct. It can be instanced using from_str on the input that is to be parsed.

Basic Usage

The basic ArgVector struct is used for operating on the whole line. It can be used to retrieve flags, arguments, and value overrides.

Value Overrides

A value override is any statement which follows the form of key=value. A value override may have the flag prefix in front of it, which will set the flag for key.

Conversion Helpers

Sometimes a string alone is not enough to convert an argument to its associated data type. For example, the arguments may correspond to entries in a hashmap. For these cases, the converter trait is used. The functions which use converters follow the form of get_x_converter where x is either single or many.

Argument iterator

The argument iterator is meant to be used to retrieve arguments in order that they were provided. Each argument that is successfully extracted from the iterator will move its index forward until there are no more arguments. This allows the user to, say, extract one or more integers, followed by a device name, then a float value, and so on.
Flags and value overrides can be retrieved from the iterator at any time. Since the iterator does not need to borrow mutably, args relative to the current position can be obtained using an offset with get_index()

Examples

todo

No runtime deps