grab-rs
A library for effortlessly grabbing input users provide to your CLI. Whether from files, stdin or just plain text on the command line, we've got you covered.
Installation
-
Add it to your Cargo.toml dependencies
# Cargo.toml [] = "0.3"
-
Import and use it
use
Usage
The main type exposed by this library is grab::Input
. An instance of Input
can
be created via grab::Config::parse
which takes a &str
as input and attempts to
parse it into a known Input
source.
Currently, known sources are:
- The actual text (
&str
) passed in as input - Your program's stdin
- A file
The default Config
uration recognizes -
for stdin per the unix tradition, and
takes cues from curl -d
by recognizing @<file path>
as a file.
This means that you can easily support all three of the most common input sources
with a single type. For example, assume we had a simple CLI tool named hello
that prints out a hello to the user...
use StructOpt;
use Input;
// We use the popular StructOpt library for our CLI skeleton
Now we can support all three of the following invocations with absolutely zero extra code:
|
;