#cli #stdin #stdout

clio

A library for parsing CLI file names

16 releases

0.2.7 Nov 15, 2022
0.2.4 Oct 3, 2022
0.2.3 Jun 22, 2022
0.2.1 Mar 25, 2022
0.1.1 Jul 15, 2020

#446 in Filesystem

Download history 1048/week @ 2023-02-05 1647/week @ 2023-02-12 1560/week @ 2023-02-19 1027/week @ 2023-02-26 1357/week @ 2023-03-05 1612/week @ 2023-03-12 931/week @ 2023-03-19 1157/week @ 2023-03-26 1187/week @ 2023-04-02 1145/week @ 2023-04-09 593/week @ 2023-04-16 814/week @ 2023-04-23 789/week @ 2023-04-30 816/week @ 2023-05-07 611/week @ 2023-05-14 1314/week @ 2023-05-21

3,630 downloads per month
Used in 3 crates

MIT license

49KB
1K SLoC

clio

clio is a rust library for parsing CLI file names.

It implements the standard unix conventions of when the file name is - then sending the data to stdin/stdout

// a cat replacement
fn main() -> clio::Result<()> {
    let args: Vec<_> = std::env::args_os().collect();
    let mut input = clio::Input::new(&args[1])?;
    std::io::copy(&mut input, &mut std::io::stdout())?;
    Ok(())
}

lib.rs:

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 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

# #[cfg(feature="clap-parse")]{
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.

Dependencies

~0–10MB
~178K SLoC