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 the args
The 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(())
}
They are also desgined to be used with structopt/clap
use clap::Parser;
use clio::*;
#[derive(Parser)]
#[clap(name = "cat")]
struct Opt {
/// Input file, use '-' for stdin
#[clap(parse(try_from_os_str = TryFrom::try_from), default_value="-")]
input: Input,
/// Output file '-' for stdout
#[clap(long, short, parse(try_from_os_str = TryFrom::try_from), default_value="-")]
output: Output,
}
fn main() {
let mut opt = Opt::parse();
std::io::copy(&mut opt.input, &mut opt.output).unwrap();
}
Features
http
bundles in ureq as a 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.
Structs
A struct that contains all the connents of a command line input stream, either std in or a file
Enums
Any error that happens when opening a stream.
A builder for Output that allows setting the size before writing. This is mostly usefull with the “http” feature for setting the Content-Length header
Type Definitions
A result with a clio::Error