A simple shell wrapper that handles argument parsing
Rust 90.6%
Other 9.4%
6 1 0

Clone this repository

https://tangled.org/fly.nonsense.now/argsh https://tangled.org/did:plc:2umgeyxs4v3o2n4oqlp4wwkv/argsh
git@tangled.org:fly.nonsense.now/argsh git@tangled.org:did:plc:2umgeyxs4v3o2n4oqlp4wwkv/argsh

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

argsh#

This is a simple shell wrapper for scripts that handles argument parsing, because argument parsing in bash is a pain in the ass.

Installation#

Build with cargo build --release and copy the resulting binary to somewhere in your path.

Usage#

Put argsh in the shebang, instead of your shell as such:

#!/bin/env -S argsh <arguments>

And you define the arguments as a semicolon separated list of arguments.

The only valid characters for an argument are a-z and -.

A plain argument such as arg is a required argument, which will be passed to the script as a positional argument.

An argument starting with # such as #arg is an optional argument, which will be passed to the script as an environment variable like $ARGSH_ARG, where all - get converted to _.

An argument starting with ? such as ?arg is a flag, which will be passed to the script as an environment variable like $ARGSH_ARG, where all - get converted to _, with the value set to 1, the value is irrelevant, just check if the variable is empty.

Any additional positional arguments passed to the script get appended after the required arguments.

Optionally, you can set the shell to use as such bash|name;count;etc, defaults to sh if ommited.

Limitations#

For the short version of arguments to work properly, all arguments must start with different characters.

Limit of 256 required arguments (if you have anything close to that please use an actual programming language).

Testing#

Run the test script as such and mess around with the arguments

./test --required indeed --also-required nice --flag --optional woah --second-optional crazy am additional