Crate clio[][src]

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

Inputs and Outputs 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 structopt::StructOpt;
use clio::*;
#[derive(StructOpt)]
#[structopt(name = "cat")]
struct Opt {
    /// Input file, use '-' for stdin
    #[structopt(parse(try_from_os_str = Input::try_from_os_str), default_value="-")]
    input: Input,

    /// Output file '-' for stdout
    #[structopt(long, short, parse(try_from_os_str = Output::try_from_os_str), default_value="-")]
    output: Output,
}

fn main() {
    let mut opt = Opt::from_args();

    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.

Enums

Any error that happens when opening a stream.

An enum that represents a command line input stream, either std in or a file

An enum that represents a command line output stream, either std out or a file

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