Expand description
clio is a library for parsing CLI file names.
It implemts the standard unix convetions of when the file name is “-” then sending the data to stdin/stdout as apropriate
Usage
Input
s and Output
s can be created directly from args in args_os
.
They will error if the file cannot be opened for any reason
// a cat replacement
fn main() -> clio::Result<()> {
for arg in std::env::args_os() {
let mut input = clio::Input::new(&arg)?;
std::io::copy(&mut input, &mut std::io::stdout())?;
}
Ok(())
}
With the clap-parse
feature they are also desgined to be used with clap 3.2.
See the older docs for examples of older clap/structopt
use clap::Parser;
use clio::*;
#[derive(Parser)]
#[clap(name = "cat")]
struct Opt {
/// Input file, use '-' for stdin
#[clap(value_parser, default_value="-")]
input: Input,
/// Output file '-' for stdout
#[clap(long, short, value_parser, default_value="-")]
output: Output,
}
fn main() {
let mut opt = Opt::parse();
std::io::copy(&mut opt.input, &mut opt.output).unwrap();
}
Features
clap-parse
Implements ValueParserFactory
for all the types and
adds a bad implmentation of Clone
to all types as well to keep clap
happy.
HTTP Client
If a url is passed to Input::new
then it will perform and HTTP GET
.
If a url is passed to Output::new
then it will perform and HTTP PUT
.
You can use SizedOutput
to set the size before the upload starts e.g.
needed if you are sending a file to S3.
http-ureq
bundles in ureq as a HTTP client.
http-curl
bundles in curl as a HTTP client.
Structs
Enums
Type Definitions
clio::Error